MySQL 8.0 也推出一段時間了,整理一篇安裝教程html
CentOS7.4系統自帶mariadbnode
[root@iZ286t0wuf9Z etc]# rpm -qa|grep mariadb mariadb-libs-5.5.56-2.el7.x86_64 [root@iZ286t0wuf9Z etc]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
部分博客須要移除 /etc/my.cnf,經實踐,本要執行卸載以前/etc目錄下有my.cnf和my.cnf.d,執行卸載以後已經一塊兒移除了。或者能夠執行下面代碼:mysql
[root@iZ286t0wuf9Z etc]# rm my.cnf
或文件不存在,會提示linux
[root@iZ286t0wuf9Z etc]# rm my.cnf rm: cannot remove ‘my.cnf’: No such file or director
檢查mysql是否存在sql
[root@iZ286t0wuf9Z etc]# rpm -qa | grep mysql [root@iZ286t0wuf9Z etc]#
沒有任何輸出表示未安裝數據庫
建立mysql組和用戶vim
(1) 先檢查是否存在centos
[root@iZ286t0wuf9Z etc]# cat /etc/group | grep mysql [root@iZ286t0wuf9Z etc]# cat /etc/passwd | grep mysql [root@iZ286t0wuf9Z etc]#
(2) 沒有輸出,則建立組和用戶bash
[root@iZ286t0wuf9Z etc]# groupadd mysql [root@iZ286t0wuf9Z etc]# useradd -g mysql mysql [root@iZ286t0wuf9Z etc]# passwd mysql Changing password for user mysql. New password: Retype new password: passwd: all authentication tokens updated successfully. [root@iZ286t0wuf9Z etc]#
準備安裝文件服務器
截圖比較多,附在文章最後,點擊跳轉
解壓安裝
(1) 把mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz文件移動到/usr/local/mysql目錄下,假設文件在/home/ftp目錄下
[root@iZ286t0wuf9Z etc]# mv /home/ftp /usr/local/mysql
(3) 解壓
[root@iZ286t0wuf9Z etc]# cd /usr/local [root@iZ286t0wuf9Z local]# tar -xvJf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz mysql-8.0.13-linux-glibc2.12-x86_64/bin/myisam_ftdump mysql-8.0.13-linux-glibc2.12-x86_64/bin/myisamchk ---------- #此處省略二百多行 mysql-8.0.13-linux-glibc2.12-x86_64... ---------- mysql-8.0.13-linux-glibc2.12-x86_64/lib/libmysqlharness.so.1 mysql-8.0.13-linux-glibc2.12-x86_64/lib/libmysqlrouter.so mysql-8.0.13-linux-glibc2.12-x86_64/lib/libmysqlrouter.so.1 [root@iZ286t0wuf9Z local]# mv mysql-8.0.13-linux-glibc2.12-x86_64 mysql
更改所屬的組和用戶
注意每次執行的目錄
[root@iZ286t0wuf9Z mysql]# mkdir data [root@iZ286t0wuf9Z mysql]# cd .. [root@iZ286t0wuf9Z local]# chown -R mysql mysql [root@iZ286t0wuf9Z local]# chgrp -R mysql mysql
準備/etc/my.cnf文件
[root@iZ286t0wuf9Z mysql]# vim /etc/my.cnf [mysql] # 設置mysql客戶端默認字符集 default-character-set=utf8mb4 [mysqld] # 設置3306端口 port = 3306 # 設置mysql的安裝目錄 basedir=/usr/local/mysql # 設置mysql數據庫的數據的存放目錄 datadir=/usr/local/mysql/data # 容許最大鏈接數 max_connections=200 # 服務端默認編碼(數據庫級別) character-set-server=utf8mb4 # 建立新表時將使用的默認存儲引擎 default-storage-engine=INNODB lower_case_table_names=1 max_allowed_packet=16M [root@iZ286t0wuf9Z mysql]# chown 777 /etc/my.cnf
執行初始化
[root@iZ286t0wuf9Z mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ -bash: bin/mysql_install_db: No such file or directory
切換到/usr/local/mysql/bin目錄下,發現確實沒有 mysql_install_db
,改爲 bin/mysqld --initialize
[root@iZ286t0wuf9Z mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
又報錯,執行下面命令
[root@iZ286t0wuf9Z mysql]# yum install -y libaio Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed --> Finished Dependency Resolution ---------- #此處省略二十多行輸出語句 ---------- Installed: libaio.x86_64 0:0.3.109-13.el7 Complete!
再執行
[root@iZ286t0wuf9Z mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ 2018-11-21T07:30:42.888897Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 26596 2018-11-21T07:30:48.222050Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: l*JsMq=uX4>k 2018-11-21T07:30:49.788339Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.13) initializing of server has completed
再執行
[root@iZ286t0wuf9Z mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld [root@iZ286t0wuf9Z mysql]# chmod +x /etc/init.d/mysqld
配置環境變量
在 /etc/profile 最後添加以下內容export PATH=$PATH:/usr/local/mysql/bin
[root@iZ286t0wuf9Z mysql]# vim /etc/profile ---------- #省略N行配置信息 ---------- unset i unset -f pathmunge #set mysql environment export PATH=$PATH:/usr/local/mysql/bin
使配置文件生效
[root@iZ286t0wuf9Z mysql]# source /etc/profile
啓動 MySQL 服務
[root@iZ286t0wuf9Z mysql]# /etc/init.d/mysqld start Starting MySQL.Logging to '/usr/local/mysql/data/iZ286t0wuf9Z.err'. .[ OK ] [root@iZ286t0wuf9Z mysql]#
設置 MySQL 服務開機啓動
此處根據參考文檔用了 chkconfig 命令,但看到提示信息以後才知道,Centos 5.7開始,
在 Centos 5.7 中服務不在是用 service 這個命令來啓動與中止,也再也不用 chkconfig 來設置開機啓動與否!在 centos7 中全部對服務的管理都集中到了 systemctl 當中; systemctl 再也不是合以前同樣依賴 /etc/init.d/ 下的腳本,它是經過配置文件來完成對服務的管理的。(參考:蔣樂興的技術隨筆)
[root@iZ286t0wuf9Z ~]# chkconfig --list Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. aegis 0:off 1:off 2:on 3:on 4:on 5:on 6:off agentwatch 0:off 1:off 2:on 3:on 4:on 5:on 6:off netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
此處暫且這樣採用 chkconfig 設置
[root@iZ286t0wuf9Z mysql]# chmod +x /etc/rc.d/init.d/mysqld [root@iZ286t0wuf9Z mysql]# chkconfig --add mysqld [root@iZ286t0wuf9Z mysql]# chkconfig --list mysqld [root@iZ286t0wuf9Z mysql]# chkconfig --level 35 mysqld on
執行 add 操做以後,list 中就會有 mysqld 了
[root@iZ286t0wuf9Z ~]# chkconfig --list Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. aegis 0:off 1:off 2:on 3:on 4:on 5:on 6:off agentwatch 0:off 1:off 2:on 3:on 4:on 5:on 6:off mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
初始化 root 密碼
並沒意料到此處有障礙,本人沒有找到初始密碼在哪裏,無奈選擇重置。而後重置比我預計的複雜一點,步驟太多,請參考另外一篇博客:MySQL 8.0 以上版本重置 root 用戶密碼
添加遠程訪問權限
在服務器上能夠登陸 root 用戶,但遠程連鏈接會提示
1130: host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server
xxx.xxx.xxx.xxx 遠程客戶端的IP地址,即當前客戶端IP地址禁止訪問。
[root@iZ286t0wuf9Z ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.13 MySQL Community Server - GPL Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select host,user from user; +-----------+------------------+ | host | user | +-----------+------------------+ | localhost | mysql.infoschema | | localhost | mysql.session | | localhost | mysql.sys | | localhost | root | +-----------+------------------+ 4 rows in set (0.00 sec) mysql>
查詢結果顯示,root容許的IP地址爲localhost,修改爲%便可。固然還有更復雜的設置,好比指定IP地址,或者指定IP區間,後續會再更新。
mysql> update user set host='%' where user='root'; Query OK, 1 row affected (0.03 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql>
到這裏就能夠遠程登陸了。
<span id="jump">附:步驟4. 準備安裝文件的過程截圖</span>
先整理這麼多了,歡迎你們共同討論。