how to install MySQL on macOS
2024-09-02 19:46:29
how to install MySQL on macOS
MySQL Community Server 8.0.21
# version
$ mysqladmin --version
# 8.0.21
$ mysql --version
# mysql Ver 8.0.21 for osx10.15 on x86_64 (Homebrew)
$ mysqladmin --version
# mysqladmin Ver 8.0.21 for osx10.15 on x86_64 (Homebrew)
# start MySQL server once
$ mysql.server start
# stop
$ mysql.server stop
# no password, connect
$ mysql -uroot
background service
# start MySQL server with background service
$ brew services start mysql
# stop
$ brew services stop mysql
MySQL commands
# 查看所有数据库
mysql> show databases;
# 创建数据库
mysql> create database test;
# 选择数据库
mysql> use test;
# 查看所有数据表
mysql> show tables;
# 创建数据表, 推荐使用大写的的关键字
mysql> create table `demo_table`(
`table_id` INT UNSIGNED AUTO_INCREMENT,
`table_title` VARCHAR(100) NOT NULL,
`table_author` VARCHAR(40) NOT NULL,
`created_date` DATE,
PRIMARY KEY (`table_id`)
);
# OR,
mysql> create table `demo_table`(`table_id` int unsigned auto_increment, `table_title` varchar(100) not null, `table_author` varchar(40) not null, `created_date` date, primary key (`table_id`));
# 操作数据表(插入数据)
mysql> insert into demo_table (table_title, table_author, created_date) VALUES ("MySQL Tutorials", "xgqfrms", now());
mysql> insert into demo_table (table_title, table_author, created_date) VALUES ("SQL Tutorials", "webgeeker", now());
# 操作数据表(查询)
mysql> select * from demo_table;
mysql> select table_title, table_author from demo_table;
mysql> select table_id, table_title, table_author, created_date from demo_table;
# \G, 格式化输出,美化
mysql> select * from demo_table\G;
# 操作数据表(修改数据)
mysql> update demo_table set table_title="DB Tutorials" where table_id=1;
# 操作数据表(删除数据)
mysql> delete from demo_table where table_id=1;
# 删除数据表
mysql> drop table demo_table;
# 删除数据库
mysql> drop database test;
MySQL 语法
# 创建数据表的 SQL通用语法
# CREATE TABLE table_name (column_name column_type, ..., column_name column_type, );
CREATE TABLE IF NOT EXISTS `demo_table`(
`table_id` INT UNSIGNED AUTO_INCREMENT,
`table_title` VARCHAR(100) NOT NULL,
`table_author` VARCHAR(40) NOT NULL,
`created_date` DATE,
PRIMARY KEY ( `table_id` )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
# INSERT INTO 语句插入数据表中数据的通用语法
INSERT INTO table_name ( field1, field2,...fieldN ) VALUES ( value1, value2,...valueN );
# 如果数据是字符型,必须使用单引号或者双引号,如:"value"
INSERT INTO demo_table
(table_title, table_author, created_date)
VALUES
("MySQL Tutorials", "xgqfrms", NOW());
# SELECT 语句查询数据表中数据的通用语法
SELECT column_name,column_name
FROM table_name
[WHERE Clause]
[LIMIT N][ OFFSET M];
# UPDATE 语句修改数据表中数据的通用语法
UPDATE table_name SET field1=new-value1, field2=new-value2
[WHERE Clause];
# DELETE 语句删除数据表中数据的通用语法
DELETE FROM table_name [WHERE Clause];
.dmg
install
mysql-8.0.21-macos10.15-x86_64.dmg
https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.21-macos10.15-x86_64.dmg
manually install bug
$ sudo chmod +x ./mysqladmin
brew
# mysql
$ brew install mysql
# daemon mode(background service)
$ brew services start mysql
$ brew services stop mysql
# avoid daemon mode(once)
$ mysql.server start
$ mysql.server stop
$ mysql -u root -p
https://flaviocopes.com/mysql-how-to-install/
https://stackoverflow.com/questions/4359131/brew-install-mysql-on-macos
MySQL 5
mysql-5.7
https://dev.mysql.com/doc/mysql-osx-excerpt/5.7/en/osx-installation-pkg.html
MySQL 8
mysql-8.0.21
mysql-8.0.21-macos10.15-x86_64.tar.gz
https://dev.mysql.com/downloads/mysql/
refs
.pkg
go1.14.7.darwin-amd64.pkg
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
最新文章
- golang time and duration
- Android 自定义title 之Action Bar
- WPF 组合快捷键
- CSS 框模型——规定了元素框处理元素内容、内边距、边框和外边距的方式
- 《Linux内核设计与实现》读书笔记(十)- 内核同步方法【转】
- C#多线程的几种实现方法
- HDU 2199 Can you solve this equation? (二分 水题)
- 兼容各浏览器中的PNG透明效果CSS定义
- 分享UI设计模型
- ToDictionary用法
- Django 学习笔记(三)模板导入
- Java开发笔记(八十三)利用注解技术检查空指针
- hadoop MapReduce
- [BZOJ 3498] [PA 2009] Cakes
- 20165325 2017-2018-2《Java程序设计》课程总结
- 为docker私有registry配置nginx反向代理
- .1-浅析express源码之入口文件
- CSS样式----CSS属性:字体属性和文本属性(图文详解)
- [搜狐科技]由浅入深理解Raft协议
- [php] cookie 跨域共享
热门文章
- SDNU_ACM_ICPC_2021_Winter_Practice_4th [个人赛]
- jQuery 真伪数组的转换
- day03 函数基本语法及特性 2. 参数与局部变量 3. 返回值 嵌套函数 4.递归 5.匿名函数 6.函数式编程介绍 7.高阶函数 8.内置函数
- (010)每日SQL学习:按字母顺序排列字符串
- 数位DP笔记
- DEDECMS:将dedecms系统的data目录迁移到web以外目录
- TZOJ6556: 嗅探器
- 自己动手实现java断点/单步调试(二)
- XV6学习(10)锁
- Linux远程拷贝scp