linux中的mysql5.6升級到5.7
阿新 • • 發佈:2019-01-01
公司伺服器使用的是5.6版本mysql,然後要升級到5.7,然而公司的mysql是使用rpm包安裝的mysql,於是我在網上各種搜尋mysql升級,終於在網上找到了一篇文章下面是文章的地址,(我是在參考人家的基礎上升級的)
注意: 我的是rpm安裝的5.6升級到5.7,使用的是編譯方法。如果您的mysql低版本是編譯方法升級的話可以用以下連結地址
1、 升級方法
升級的方法一般有兩類:
利用mysqldump來直接匯出sql檔案,匯入到新庫中,這種方法是最省事兒的,也是最保險的,缺點的話,也顯而易見,大庫的mysqldump費時費力。
直接替換掉mysql的安裝目錄和my.cnf,利用mysql_upgrade
來完成系統表的升級,這種方法需要備份原有的檔案,但屬於物理拷貝,速度較快。缺點的話,跨版本升級不推薦這麼做,比如mysql5.1升級到mysql5.6,mysql5.5升級到mysql5.7等。
我的方法是參考第二種方法升級,用5.7的改掉rpm安裝的5.6的mysql檔案路徑,修改相應的/etc/my.cnf,/etc/init.d/mysql和/etc/init.d/mysqld
2、rpm安裝mysql5.6的環境
- 客戶端程式和指令碼:/usr/bin
- my.cnf位置:/etc/my.cnf
- 資料庫檔案目錄:/var/lib/mysql
- 升級前的mysql版本
[[email protected] ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 341458
Server version: 5.6.31-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> select version();
+------------+
| version() |
+------------+
| 5.6.31-log |
+------------+
1 row in set (0.00 sec)
3、開始 升級
- 3.1、去官網下載最新5.7版本mysql 選則 Linux-Generic 通用型別 mysql下載地址 我選擇的x86_64的,下載後用ftp上傳到伺服器你的放檔案的資料夾中
- 3.2、備份:/etc/my.cnf
[[email protected] home]# cp /etc/my.cnf /etc/my_56.cnf
- 3.3、解壓:
[[email protected] home]# tar -zxvf mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz
- 3.4、停止mysql
[[email protected] home]# service mysql stop
- 3.5、移動:把解壓好的mysql移動到/usr/local/中
[root@localhost home]# mv mysql-5.7.16-linux-glibc2.5-x86_64 /usr/local/mysql
[root@localhost home]# chown -R mysql. /usr/local/mysql
[root@localhost home]# cd /usr/local/mysql/
[root@localhost mysql]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
[root@localhost mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
- 3.6、 編譯/etc/my.cnf
[client]
port=3306
socket=/var/lib/mysql/mysql.sock #你的sock檔案目錄
default-character-set=utf8
[mysql]
no-auto-rehash
default-character-set=utf8
[mysqld]
port=3306
character-set-server=utf8
socket=/var/lib/mysql/mysql.sock #你的sock檔案目錄
basedir=/usr/local/mysql
datadir=/var/lib/mysql #你的資料庫檔案目錄
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysqldump]
quick
max_allowed_packet=32M
[myisamchk]
key_buffer=16M
sort_buffer_size=16M
read_buffer=8M
write_buffer=8M
[mysqld_safe]
open-files-limit=8192
log-error=/var/lib/mysql/error.log #你的錯誤日誌檔案目錄
#pid-file=/data/mysql/mysqld.pid #你的pid檔案目錄,我的沒配置
根據自己的情況新增my.cnf配置
3.7、配置編譯/etc/init.d/mysqld
#datadir=/usr/local/mysql/data #修改成你的資料庫檔案目錄
datadir=/var/lib/mysql
- 3.8、啟動mysql
[[email protected] mysql]# /etc/init.d/msyqld start
[[email protected] support-files]# ps -ef|grep mysql
root 6966 1 0 Dec14 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.pid
mysql 7168 6966 0 Dec14 pts/1 00:00:13 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/var/lib/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/lib/mysql/error.log --open-files-limit=8192 --pid-file=/var/lib/mysql/localhost.pid --socket=/var/lib/mysql/mysql.sock --port=3306
root 7270 7244 0 00:27 pts/2 00:00:00 vim mysql.server
root 7287 6165 0 01:49 pts/1 00:00:00 grep mysql
升級成功,然後再升級字典,否則會在錯誤日誌中看到很多錯誤
- 3.9、升級字典
[[email protected] mysql]# /usr/local/mysql/bin/mysql_upgrade -uroot -pMANAGER
mysql_upgrade: [Warning] Using a password on the command line interface can be insecure.
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv OK
mysql.db OK
mysql.engine_cost OK
mysql.event OK
mysql.func OK
mysql.general_log OK
mysql.gtid_executed OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.innodb_index_stats OK
mysql.innodb_table_stats OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.server_cost OK
mysql.servers OK
mysql.slave_master_info OK
mysql.slave_relay_log_info OK
mysql.slave_worker_info OK
mysql.slow_log OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
Upgrading the sys schema.
Checking databases.
helei.helei OK
sys.sys_config OK
Upgrade process completed successfully.
Checking if update is needed.
—如果升級報錯的話,檢查自己的my.cnf檔案,看其中是否有自己不需要的配置,我的就是裡面有多餘的配置,註釋或刪掉就可
- 3.10、重啟mysql
[root@localhost mysql]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
升級後的版本
[[email protected] mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> select version();
+-----------+
| version() |
+-----------+
| 5.7.16 |
+-----------+
1 row in set (0.00 sec)
mysql>
總結
- 直接用/etc/my.cnf 中直接指定basedir=/usr/local/mysq 即可
- 然後可以刪除掉其中的以前5.6的mysql資料夾(我只刪掉查出來的,沒有詳細刪)
- /usr/lib64/mysql
- /usr/include/mysql
- /usr/bin/mysql
- /usr/share/man/man1/mysql.1.gz
[root@localhost ~]# whereis mysql
mysql: /usr/bin/mysql /usr/local/mysql /usr/lib64/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
- 自己研究的,用navicat也連線測試,能連線到,如果連線不上則執行:
mysql> grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;
mysql> flush privileges;
- 進行賦權,還有就是開房3306埠
- 如果啟動mysql報缺少pid檔案什麼的,可以去網上搜下,如果網上的方法都不行的話就嘗試刪除資料庫檔案目錄中的 ib_logfile0、ib_logfile1 這兩個檔案,我的有次就是這樣解決了