在mysql安裝前如果之前安裝過mysql,就要把mysql全部都刪除。
1,下載mysql安裝包
rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
2,安裝mysql
yum install -y mysql-server
3,設置開機啓動Mysql
systemctl enable mysqld.service
4,檢查是否已經安裝了開機自動啓動
systemctl list-unit-files | grep mysqld
5,設置開啓服務
systemctl start mysqld.service
6,查看MySql默認密碼
grep 'temporary password' /var/log/mysqld.log
7,登陸MySql
mysql -u root -p
8,設置密碼的驗證強度等級
set global validate_password_policy=LOW;
9,設置密碼位數
set global validate_password_length=7;
10,設置mysql密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123';
11,開啓遠程登錄,授權root遠程登錄
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root123' WITH GRANT OPTION;
12,命令立即執行生效
flush privileges;
這樣mysql就已經基本安裝完成。
設置mysql的編碼格式爲utf8
修改mysql的my.cnf文件中的字符集鍵值
在[client]下追加:
default-character-set=utf8
在[mysqld]下追加:
character-set-server=utf8
在[mysql]下追加:
default-character-set=utf8
mysql的相關操作命令
1,重啓MySql服務
service mysqld restart
2,啓動MySQL服務
systemctl start mysqld
3,查看MySQL服務狀態
systemctl status mysqld
4,關閉MySQL服務
systemctl stop mysqld