安裝環(huán)境:CentOS7 64位 MINI版傅是,安裝MySQL5.7
在MySQL官網中下載YUM源rpm安裝包:http://dev.mysql.com/downloads/repo/yum/
# 下載mysql源安裝包
shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安裝mysql源
shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm
檢查mysql源是否安裝成功
shell> yum repolist enabled | grep "mysql.*-community.*"
看到上圖所示表示安裝成功
2、安裝MySQL
shell> yum install mysql-community-server
3留荔、啟動MySQL服務
shell> systemctl start mysqld
查看MySQL的啟動狀態(tài)
shell> systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since 五 2016-06-24 04:37:37 CST; 35min ago
Main PID: 2888 (mysqld)
CGroup: /system.slice/mysqld.service
└─2888 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
6月 24 04:37:36 localhost.localdomain systemd[1]: Starting MySQL Server...
6月 24 04:37:37 localhost.localdomain systemd[1]: Started MySQL Server.
4、開機啟動
shell> systemctl enable mysqldshell> systemctl daemon-reload
5怜奖、修改root默認密碼
mysql安裝完成之后妖胀,在/var/log/mysqld.log文件中給root生成了一個默認密碼。通過下面的方式找到root默認密碼档礁,然后登錄mysql進行修改:
shell> grep 'temporary password' /var/log/mysqld.log
![](http://upload-images.jianshu.io/upload_images/5406094-7ae2261a4f7acbf9.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
shell> mysql -uroot -pmysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
或者
mysql> set password for 'root'@'localhost'=password('MyNewPass4!');
注意:mysql5.7默認安裝了密碼安全檢查插件(validate_password)角钩,默認密碼檢查策略要求密碼必須包含:大小寫字母、數(shù)字和特殊符號呻澜,并且長度不能少于8位递礼。否則會提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements錯誤,如下圖所示: 通過msyql環(huán)境變量可以查看密碼策略的相關信息:
mysql> show variables like '%password%';
MySQL官網密碼策略詳細說明:http://dev.mysql.com/doc/refman/5.7/en/validate-password-options-variables.html#sysvar_validate_password_policy
修改密碼策略
在/etc/my.cnf文件添加validate_password_policy配置羹幸,指定密碼策略
選擇0(LOW)脊髓,1(MEDIUM),2(STRONG)其中一種栅受,選擇2需要提供密碼字典文件validate_password_policy=0
如果不需要密碼策略将硝,添加my.cnf文件中添加如下配置禁用即可:
validate_password = off
重新啟動mysql服務使配置生效:
systemctl restart mysqld
6、添加遠程登錄用戶
默認只允許root帳戶在本地登錄屏镊,如果要在其它機器上連接mysql袋哼,必須修改root允許遠程連接,或者添加一個允許遠程連接的帳戶闸衫,為了安全起見涛贯,我添加一個新的帳戶:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yangxin'@'%' IDENTIFIED BY 'Yangxin0917!' WITH GRANT OPTION;
7、配置默認編碼為utf8
修改/etc/my.cnf配置文件蔚出,在[mysqld]下添加編碼配置弟翘,如下所示:
[mysqld]character_set_server=utf8init_connect='SET NAMES utf8'
重新啟動mysql服務,查看數(shù)據(jù)庫默認編碼如下所示:
默認配置文件路徑:
配置文件:/etc/my.cnf 日志文件:/var/log//var/log/mysqld.log
服務啟動腳本:/usr/lib/systemd/system/mysqld.service socket
文件:/var/run/mysqld/mysqld.pid