養(yǎng)成良好的記錄習(xí)慣
時(shí)間:2019年10月12日
作者:黃黃
1.安裝MySQL的yum源
yum localinstall https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
2.安裝MySQL
yum install mysql-community-server
3.進(jìn)行mysql8.0一些小細(xì)節(jié)的設(shè)置
設(shè)置是否區(qū)分表名大小寫
mysql8.0以后都是默認(rèn)區(qū)分大小寫更振,如果修改需要添加對(duì)應(yīng)的設(shè)置,(注意要在mysql8.0一開始沒做任何設(shè)置的時(shí)候進(jìn)行配置,不然啟動(dòng)mysql有可能會(huì)失敗商佛。)linux默認(rèn)mysql的配置文件地址是/etc/my.cnf
vi /etc/my.cnf
加入lower_case_table_names=1(0是區(qū)分大小寫弃舒,1是不區(qū)分大小寫殴边,一般是業(yè)務(wù)上是不進(jìn)行區(qū)分的)
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/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 the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_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
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
lower_case_table_names=1
4.啟動(dòng)MySQL服務(wù)并設(shè)置開機(jī)自啟
systemctl start mysqld.service
systemctl enable mysqld.service
5.獲取臨時(shí)密碼
grep 'A temporary password is generated for root@localhost' /var/log/mysqld.log |tail -1;
輸出如下:
2018-09-01T17:13:30.385800Z 5 [Note] [MY-010454] [Server] A
temporary password is generated for root@localhost: NqLQAN?(m1=Q
NqLQAN?(m1=Q為你的臨時(shí)密碼
6.更改密碼
先設(shè)置密碼策略睡腿,不設(shè)置不能修改為簡(jiǎn)單的密碼先登錄mysql,mysql8.0密碼校驗(yàn)比較嚴(yán)苛
登陸MySQL
mysql -u root -p
- 輸入密碼NqLQAN?(m1=Q回車登陸成功
設(shè)置策略
set global validate_password.policy=0;
set global validate_password.length=6;
更改密碼
還提供使用安全安裝腳本修改密碼梯醒,有需要可以自行研究
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密碼';
7. 添加遠(yuǎn)程賬戶
MySQL 8.0的安全策略比之前的版本要嚴(yán)格很多灶芝,如果想通過遠(yuǎn)程訪問不能直接改my.conf了郑原,需要到MySQL中去設(shè)置
創(chuàng)建遠(yuǎn)程用戶
添加用戶和密碼到監(jiān)聽ip,注意這里的ip應(yīng)該是本機(jī)與外界通信的物理ip,%是指所有ip相對(duì)來講不夠安全夜涕,安全考慮多的慎用
CREATE USER '賬號(hào)'@'%' IDENTIFIED WITH mysql_native_password BY '密碼';
為用戶設(shè)置權(quán)限
授予所有數(shù)據(jù)庫所有的權(quán)限
GRANT ALL PRIVILEGES ON *.* TO '賬號(hào)'@'%';
授予單個(gè)數(shù)據(jù)庫(test數(shù)據(jù)庫)所有的權(quán)限
grant all privileges on test.* to '賬號(hào)'@'%';
授予對(duì)應(yīng)的操作權(quán)限
常見的權(quán)限有select,insert,update,delete,create,drop犯犁,分別是查、增钠乏、改栖秕、刪、創(chuàng)建晓避、清空簇捍,前四種是對(duì)表數(shù)據(jù)的操作,后兩種是對(duì)表的操作俏拱∈钏埽可根據(jù)自己的需要進(jìn)行權(quán)限授予。舉例:
grant select,insert on test to '賬號(hào)'@'%';
刷新策略
FLUSH PRIVILEGES;