安裝環境/工具
1、Linux(CentOS 7.4版)
2、mysql-8.0.12-el7-x86_64.tar.gz
安裝步驟
參考:https://dev.mysql.com/doc/refman/8.0/en/installing.html
1、下載mysql解壓版(mysql-8.0.12-el7-x86_64.tar.gz),下載地址http://dev.mysql.com/downloads/mysql/;
2、解壓mysql安裝文件
命令:tar zxvf mysql-8.0.12-el7-x86_64.tar.gz
3、復制解壓后的mysql到軟件目錄:
命令:cp -r mysql-8.0.12-el7-x86_64 /data/soft/
4、添加系統mysql組和mysql用戶:
命令:groupadd mysql
命令:useradd -r -g mysql -s /bin/false mysql
5、安裝數據庫
a、進入安裝mysql軟件目錄:
命令: cd /data/soft/mysql-8.0.12-el7-x86_64
mysql目錄結構
目錄 | 目錄的內容 |
---|---|
bin |
mysqld服務器,客戶端和實用程序 |
docs |
信息格式的MySQL手冊 |
man |
Unix手冊頁 |
include |
包含(標題)文件 |
lib |
圖書館 |
share |
用於數據庫安裝的錯誤消息,字典和SQL |
support-files |
其他支持文件 |
b、修改當前目錄擁有者為mysql用戶:
命令: chown -R mysql:mysql ./
c、配置mysql配置文件,命令:vim /etc/my.cnf
1 [client] 2 default-character-set=utf8 3 socket=/data/soft/mysql-8.0.12-el7-x86_64/data/mysql.sock 4 5 [mysqld] 6 7 # 設置mysql客戶端連接服務端時默認使用的端口 8 port=3306 9 10 basedir=/data/soft/mysql-8.0.12-el7-x86_64 # 設置mysql的安裝目錄 11 datadir=/data/soft/mysql-8.0.12-el7-x86_64/data 12 13 socket=/data/soft/mysql-8.0.12-el7-x86_64/data/mysql.sock 14 15 # Disabling symbolic-links is recommended to prevent assorted security risks 16 symbolic-links=0 17 18 # Settings user and group are ignored when systemd is used. 19 # If you need to run mysqld under a different user or group, 20 # customize your systemd unit file for mariadb according to the 21 # instructions in http://fedoraproject.org/wiki/Systemd 22 23 [mysqld_safe] 24 log-error=/data/log/mysql-log/error.log 25 pid-file=/data/soft/mysql-8.0.12-el7-x86_64/data/mysql.pid 26 27 # 28 # include all files from the config directory 29 # 30 !includedir /etc/my.cnf.d
d、創建日志文件(:wq保存退出,創建一個空文件即可),並且授權:
命令: vim /data/log/mysql-log/error.log
命令: chown mysql:mysql /data/log/mysql-log/error.log
e、初始化數據目錄,包括mysql
包含初始MySQL授權表的 數據庫,該表確定如何允許用戶連接到服務器
命令:bin/mysqld --initialize --user=mysql
若出現:./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
因為沒有安裝libaio
庫,MySQL依賴於libaio
庫,安裝libaio
庫
命令:yum search libaio
命令:yum install libaio
初始化數據庫后,記錄中出現了初始密碼,沒有初始密碼可以去日志中查找,用戶名:root,密碼:!+Ejv-)lu0r>
f、如果您希望服務器能夠部署並自動支持安全連接,請使用 mysql_ssl_rsa_setup實用程序創建默認的SSL和RSA文件
命令:bin/mysql_ssl_rsa_setup
6.添加開機啟動mysql服務和啟動mysql服務
添加mysql服務
命令:cp support-files/mysql.server /etc/init.d/mysql
啟動mysql服務
命令:service mysql start
關閉mysql服務
命令:service mysql stop
添加開機啟動服務
命令:chkconfig --add mysql
7、添加mysql系統命令,修改系統文件,添加內容,是內容生效。
修改系統文件命令:vim /etc/profile
內容生效命令:source /etc/profile
8.修改mysql的root用戶密碼,root初始密碼為在日志中上面有提到
a、進入數據庫命令:mysql -u root -p
b、修改密碼命令:alter user 'root'@'localhost' identified by 'newpassword';
c、刷新權限命令:flush privileges;
退出數據庫,即可用root用戶和新密碼登錄數據庫
d、退出數據庫
命令:quit;
9、查看數據庫user表,注意mysql 5.8密碼字段改為authentication_string。
命令:select host,user,authentication_string from user;
10、配置遠程登錄
修改遠程登登錄命令:update user set `Host` = '%' where `User` = 'root' limit 1;
然后刷新權限命令:flush privileges;
完成以上步驟即可遠程連接MySQL數據庫了
11、新增用戶
命令:create user 'test'@'%' identified by '123456';
12、給用戶授權
命令:grant all privileges on *.* to 'test'@'%' with grant option;
13、如果是用navicat連接,由於mysql8的加密方式不同,需要使用navicat的加密方式,修改密碼
命令:alter user 'test'@'%' identified with mysql_native_password by '123456';