- 下載并安裝MySQL官方的 Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
使用上面的命令就直接下載了安裝用的Yum Repository,大概25KB的樣子,然后就可以直接yum安裝了肴甸。
yum -y install mysql57-community-release-el7-10.noarch.rpm
- 安裝 MySQL 服務(wù)
yum -y install mysql-community-server
這個(gè)過(guò)程比較漫長(zhǎng).....
- MySQL 配置
- 啟動(dòng) MySQL
systemctl start mysqld.service
- 修改
/etc/my.cnf
,增加bind-address=0.0.0.0
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# 綁定 ip
bind-address=0.0.0.0
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
重啟mysql服務(wù)使配置生效
systemctl restart mysqld
- 查看 MySQL 運(yùn)行狀態(tài),運(yùn)行狀態(tài)如圖:
systemctl status mysqld
- 查看
root@localhost
密碼,grep "password" /var/log/mysqld.log
進(jìn)入數(shù)據(jù)庫(kù)
mysql -u root -p
崩侠,輸入初始密碼lGbaxrzas9.E
修改
root@localhost
密碼,ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
其中‘new password’替換成你要設(shè)置的密碼坷檩,注意:密碼設(shè)置必須要大小寫字母數(shù)字和特殊符號(hào)(,/';:等),不然不能配置成功却音,如果要修改為root這樣的弱密碼,需要進(jìn)行以下配置:查看當(dāng)前密碼策略
show variables like '%password%';
策略說(shuō)明
validate_password.length 是密碼的最小長(zhǎng)度矢炼,默認(rèn)是8系瓢,我們把它改成6
輸入:set global validate_password.length=6;
validate_password.policy 驗(yàn)證密碼的復(fù)雜程度,我們把它改成0
輸入:set global validate_password.policy=0;
validate_password.check_user_name 用戶名檢查句灌,用戶名和密碼不能相同夷陋,我們也把它關(guān)掉
輸入:set global validate_password.check_user_name=off;
- 修改密碼策略
添加validate_password_policy配置
選擇0(LOW),1(MEDIUM)胰锌,2(STRONG)其中一種骗绕,選擇2需要提供密碼字典文件
[root@slave1 ~]# vim /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# 綁定 ip
bind-address=0.0.0.0
# 添加validate_password_policy配置
validate_password_policy=0
# 關(guān)閉密碼策略
validate_password = off
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
重啟mysql服務(wù)使配置生效
systemctl restart mysqld
- 開啟mysql的遠(yuǎn)程訪問(wèn)
執(zhí)行以下命令開啟遠(yuǎn)程訪問(wèn)限制(注意:下面命令開啟的IP是 192.168.0.1,如要開啟所有的匕荸,用%代替IP):
grant all privileges on *.* to 'root'@'192.168.0.1' identified by 'password' with grant option;
然后再輸入下面兩行命令
flush privileges;
exit;
- 為 firewalld 添加開放端口
添加mysql端口3306
firewall-cmd --zone=public --add-port=3306/tcp --permanent
# 重新加載
firewall-cmd --reload
- 修改mysql的字符編碼(不修改會(huì)產(chǎn)生中文亂碼問(wèn)題)
顯示原來(lái)編碼:
show variables like '%character%';
修改/etc/my.cnf
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
重啟mysql服務(wù)使配置生效
systemctl restart mysqld