Linux下安裝Mysql5.7.x資料庫
阿新 • • 發佈:2019-02-20
首先檢查是否存在mariadb 如果存在需要解除安裝
ps -ef| grep mariadb
mysql 31760 28814 0 18:16 pts/1 00:00:00 grep --color=auto mariadb
rpm -qa | grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
解除安裝
rpm -e mariadb-libs-5.5.52-1.el7.x86_64
會提示有依賴於這的安裝包,那麼就強制解除安裝,不查檢依賴:
rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
將所有的mariadb安裝包都刪除,然後自行安裝MySQL就可以了
1---->rpm -qa|grep -i mysql 檢查是否已經有安裝,可見已經安裝了庫檔案,應該先解除安裝,不然會出現覆蓋錯誤。注意卸:載時使用了--nodeps選項,忽略了依賴關係
2---->檢查使用者組是否儲存cat /etc/group | grep mysql
檢查使用者是否存在cat /etc/passwd | grep mysql
[mysql@oracledb_178 ~]$ cat /etc/group | grep mysql
mysql:x:1002:
[mysql@oracledb_178 ~]$ cat /etc/passwd | grep mysql
mysql:x:1001:1002::/home/mysql:/bin/bash
3---->如果不存在新建
groupadd mysql 建立使用者組
useradd -r -g mysql mysql 建立使用者 useradd -r引數表示mysql使用者是系統使用者,不可用於登入系統
進入mysql資料夾,也就是mysql所在的目錄,並更改所屬的組和使用者
chown -R mysql .
chgrp -R mysql .
4---->解壓
tar xvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.18-linux-glibc2.5-x86_64 ../mysql-5.7.18
5---->執行mysql_install_db指令碼 報錯 mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2017-09-01 11:50:57 [ERROR] The data directory needs to be specified.mysql_install_db 已經不再推薦使用了,建議改成 mysqld –initialize 完成例項初始化
5.7.X的版本使用mysqld
執行命令:
./mysqld --user=mysql --datadir=/home/mysql/mysql-5.7.18/data --basedir=/home/mysql/mysql-5.7.18 --initialize
結果如下:必須記住A temporary password is generated for root@localhost: Cuc_gue<B7Li
017-09-01T10:22:39.683534Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-09-01T10:22:39.683770Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2017-09-01T10:22:39.684125Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-09-01T10:22:42.210352Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-09-01T10:22:42.696775Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-09-01T10:22:42.776470Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 7d47ff18-8eff-11e7-
9079-000c2918d28c.2017-09-01T10:22:42.780141Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-09-01T10:22:42.781062Z 1 [Note] A temporary password is generated for root@localhost: Cuc_gue<B7Li
6----> 檢測一下是否能啟動
./mysql.server start
./mysql.server: line 239: my_print_defaults: command not found
./mysql.server: line 259: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
修改./mysql.server檔案的
basedir=/home/mysql/mysql-5.7.18
datadir=/home/mysql/mysql-5.7.18/data
執行
$ ./mysql.server start
Starting MySQL. SUCCESS!
6---->配置my.cnf
[mysqld]
basedir=/home/mysql/mysql-5.7.18
datadir=/home/mysql/mysql-5.7.18/data
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
[mysql]
default-character-set=utf8
[mysqld]
character_set_server=utf8
[mysqld_safe]
log-error=/home/mysql/mysql-5.7.18/data/error.log
pid-file=/home/mysql/mysql-5.7.18/data/oracledb_178.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
7---->拷貝啟動檔案到/etc/init.d/下並重命令為mysqld
cp /home/mysql/mysql-5.7.18/support-files/mysql.server /etc/init.d/mysqld
8------->增加執行許可權
chmod 755 /etc/init.d/mysqld
9------->檢查自啟動項列表中沒有mysqld這個,如果沒有就新增mysqld:
chkconfig --list mysqld
chkconfig --add mysqld
10---------->用這個命令設定開機啟動:
chkconfig mysqld on
11---------->停止mysql服務
service mysqld stop
重啟mysql服務
service mysqld restart
12--->初始化mysql使用者root的密碼 先將mysql服務停止 # service mysqld stop 進入mysql安裝目錄, cd mysql-5.7.18/bin 執行 ./mysqld_safe --skip-grant-tables --skip-networking& 然後開啟另一個新的ssl視窗 cd mysql-5.7.18/bing ./mysql -u root mysql 執行 mysql> use mysql; Database changed mysql> UPDATE user SET password=PASSWORD('123456') WHERE user='root'; ERROR 1054 (42S22): Unknown column 'password' in 'field list' mysql> update user set authentication_string = PASSWORD('123456') where user = 'root'; 執行 mysql>\s -------------- ./mysql Ver 14.14 Distrib 5.7.18, for linux-glibc2.5 (x86_64) using EditLine wrapper
Connection id: 3 Current database: mysql Current user: root@ SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.7.18 MySQL Community Server (GPL) Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: latin1 Db characterset: latin1 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /tmp/mysql.sock Uptime: 3 min 57 sec Threads: 1 Questions: 43 Slow queries: 0 Opens: 127 Flush tables: 1 Open tables: 52 Queries per second avg: 0.181 -------------- mysql> exit; 12--->重新啟動mysql服務, 用新密碼連線mysql mysql@oracledb_178 bin]$ ./mysql -uroot -p 13---> 遠端授權 grant all privileges on *.* to 'root'@'%' identified by '123456'; grant all on *.* to 'root'@'%' identified by '123456'; ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement 出現上面的錯誤只需要執行mysql>flush privileges; 在執行 mysql> grant all on *.* to 'root'@'%' identified by '123456'; Query OK, 0 rows affected, 1 warning (0.00 sec) 客戶端navacat無法連線關閉防火牆 關閉firewall: systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall開機啟動 firewall-cmd --state #檢視預設防火牆狀態(關閉後顯示notrunning,開啟後顯示running) 12--->最後重新啟動一下,然後客戶端就可以連線mysql了
12--->初始化mysql使用者root的密碼 先將mysql服務停止 # service mysqld stop 進入mysql安裝目錄, cd mysql-5.7.18/bin 執行 ./mysqld_safe --skip-grant-tables --skip-networking& 然後開啟另一個新的ssl視窗 cd mysql-5.7.18/bing ./mysql -u root mysql 執行 mysql> use mysql; Database changed mysql> UPDATE user SET password=PASSWORD('123456') WHERE user='root'; ERROR 1054 (42S22): Unknown column 'password' in 'field list' mysql> update user set authentication_string = PASSWORD('123456') where user = 'root'; 執行 mysql>\s -------------- ./mysql Ver 14.14 Distrib 5.7.18, for linux-glibc2.5 (x86_64) using EditLine wrapper
Connection id: 3 Current database: mysql Current user: root@ SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.7.18 MySQL Community Server (GPL) Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: latin1 Db characterset: latin1 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /tmp/mysql.sock Uptime: 3 min 57 sec Threads: 1 Questions: 43 Slow queries: 0 Opens: 127 Flush tables: 1 Open tables: 52 Queries per second avg: 0.181 -------------- mysql> exit; 12--->重新啟動mysql服務, 用新密碼連線mysql mysql@oracledb_178 bin]$ ./mysql -uroot -p 13---> 遠端授權 grant all privileges on *.* to 'root'@'%' identified by '123456'; grant all on *.* to 'root'@'%' identified by '123456'; ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement 出現上面的錯誤只需要執行mysql>flush privileges; 在執行 mysql> grant all on *.* to 'root'@'%' identified by '123456'; Query OK, 0 rows affected, 1 warning (0.00 sec) 客戶端navacat無法連線關閉防火牆 關閉firewall: systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall開機啟動 firewall-cmd --state #檢視預設防火牆狀態(關閉後顯示notrunning,開啟後顯示running) 12--->最後重新啟動一下,然後客戶端就可以連線mysql了