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 發布文章使用:只允許注冊用戶才可以訪問!