linux下安裝mysql8.0(二進制方式)


環境

OS:Centos 7

 

1.下載安裝介質
官網下載
我這里下載的是8.0.17
mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz

2.創建mysql用戶和用戶組
#groupadd mysql
#useradd -g mysql mysql
#passwd mysql

3.下載解壓安裝
[root@localhost soft]# tar -xvf mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz
[root@localhost soft]# mv mysql-8.0.17-linux-glibc2.12-x86_64 /opt/mha/mysql8

4.創建相應的目錄
[root@localhost mysql8]# mkdir data ##數據文件目錄
[root@localhost mysql8]# mkdir conf ## 配置文件目錄
[root@localhost mysql8]# mkdir redolog ##redo日志文件
[root@localhost mysql8]# mkdir -p mysqllog/relaylog ##主從環境relaylog
[root@localhost mysql8]# mkdir -p mysqllog/logfile ##錯誤日志文件
[root@localhost mysql8]# mkdir -p mysqllog/binlog ##binlog文件
[root@localhost mysql8]# mkdir ibdata ##ibdata文件


5.初始化數據庫
root賬戶下
[root@localhost bin]# ./mysqld --initialize --user=mysql --basedir=/opt/mha/mysql8 --datadir=/opt/mha/mysql8/data
2019-09-05T08:25:17.210466Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2019-09-05T08:25:17.210613Z 0 [System] [MY-013169] [Server] /opt/mha/mysql8/bin/mysqld (mysqld 8.0.17) initializing of server in progress as process 25951
2019-09-05T08:25:38.288278Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: vew-DWj=q4r<
2019-09-05T08:25:49.555673Z 0 [System] [MY-013170] [Server] /opt/mha/mysql8/bin/mysqld (mysqld 8.0.17) initializing of server has complete

這里初始化密碼為vew-DWj=q4r<

若不想要初始化密碼,不需要密碼的話可以采用如下方法初始化話
./mysqld --initialize-insecure --user=mysql --basedir=/opt/mha/mysql8 --datadir=/opt/mha/mysql8/data

6.配置文件
vi /opt/mha/mysql8/conf/my.cnf
[mysqld]
server-id=134
port=13306
basedir=/opt/mha/mysql8
datadir=/opt/mha/mysql8/data
socket=/opt/mha/mysql8/mysql.sock
character-set-server=utf8mb4
max_connections = 1500
binlog_format=row
log-bin=/opt/mha/mysql8/mysqllog/binlog/binlog
slow_query_log_file=/opt/mha/mysql8/mysqllog/logfile/slow-query.log
log-error=/opt/mha/mysql8/mysqllog/logfile/mysql-err.log
relay-log-index=/opt/mha/mysql8/mysqllog/relaylog/slave-relay-bin.index
relay-log=/opt/mha/mysql8/mysqllog/relaylog/relaylog-binlog
gtid_mode=ON
enforce_gtid_consistency = ON
event_scheduler=1


7.修改目錄權限
[root@localhost mha]# cd /opt
[root@localhost opt]# chown -R mysql:mysql ./mha


8.啟動
(在mysql用戶下執行)
[mysql@localhost bin]$ /opt/mha/mysql8/bin/mysqld_safe --defaults-file=/opt/mha/mysql8/conf/my.cnf --user=mysql &

9.登陸數據庫修改相應用戶密碼
[mysql@localhost bin]$ ./mysql -h 127.0.0.1 -uroot -P13306 -S /opt/mha/mysql8/mysql.sock -p

mysql> select version();
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

提示修改密碼
alter user 'root'@'localhost' identified by 'mysql';
flush privileges;

10.重新登錄
[mysql@localhost bin]$ ./mysql -h localhost -uroot -P13306 -S /opt/mha/mysql8/mysql.sock -pmysql

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.17 |
+-----------+
1 row in set (0.00 sec)

11.創建開發用戶
在mysql8.0創建用戶和授權和之前不太一樣了,其實嚴格上來講,也不能說是不一樣, 只能說是更嚴格, mysql8.0需要先創建用戶(創建用戶時要帶@並指定地址, 則grant授權時的地址就是這個@后面指定的!, 否則grant授權就會報錯!)和設置密碼,然后才能授權。
create user 'hxl'@'%' identified by 'mysql';
grant all privileges on *.* to 'hxl'@'%' with grant option;

采用5.7之前的辦法創建用戶會報錯
mysql> grant all privileges on *.* to 'hxl01'@'%' identified by 'mysql';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by 'mysql'' at line 1


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM