一蔓纠、安裝
1辑畦、執(zhí)行安裝命令
brew install mysql
2、安裝完后啟動mysql
mysql.server start
3腿倚、執(zhí)行安全設(shè)置
mysql_secure_installation
顯示如下
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
按照提示選擇密碼等級纯出,并設(shè)置root密碼
二、創(chuàng)建新的數(shù)據(jù)庫、用戶并授權(quán)
1暂筝、登錄mysql
mysql -u root -p
按提示輸入root密碼
root@poksi-test-2019:~# mysql -u root -p
Enter password:
2箩言、創(chuàng)建數(shù)據(jù)庫
create database retail_db character set utf8mb4;
3、創(chuàng)建用戶
create user 'retail_u'@'%' identified by 'retail_PWD_123';
4焕襟、授權(quán)用戶
grant all privileges on retail_db.* to 'retail_u'@'%';
flush privileges;
5陨收、查看當(dāng)前的數(shù)據(jù)庫
show databases;
6、顯示當(dāng)前數(shù)據(jù)庫的表單
show tables
三胧洒、建表
CREATE TABLE t_user(
key_id VARCHAR(255) NOT NULL PRIMARY KEY, -- id 統(tǒng)一命名為key_id
user_name VARCHAR(255) NOT NULL ,
password VARCHAR(255) NOT NULL ,
phone VARCHAR(255) NOT NULL,
deleted INT NOT NULL DEFAULT 0, -- 邏輯刪除標(biāo)志默認值
create_time timestamp NULL default CURRENT_TIMESTAMP, -- 創(chuàng)建時間默認值
update_time timestamp NULL default CURRENT_TIMESTAMP -- 修改時間默認值
) ENGINE=INNODB AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8mb4;
四畏吓、檢查mysql服務(wù)狀態(tài)
先退出mysql命令行,輸入命令
systemctl status mysql.service
顯示如下結(jié)果說明mysql服務(wù)是正常的
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2019-05-22 10:53:13 CST; 13min ago
Main PID: 16686 (mysqld)
Tasks: 29 (limit: 4667)
CGroup: /system.slice/mysql.service
└─16686 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
May 22 10:53:12 poksi-test-2019 systemd[1]: Starting MySQL Community Server...
May 22 10:53:13 poksi-test-2019 systemd[1]: Started MySQL Community Server.