1、備份原數據庫
[root@www ~] #mysqldump -u root –p -E –all-database > /home/db-backup.sql
加-E是因為mysqldump默認並不處理mysql的事件,需要自己指明是否導出事件。
copy一份my.cnf,待安裝mysql5.7的時候參照。
[root@www ~]# cp /etc/my.cnf /home/my.cnf
停止mysql服務
[root@www ~]# service mysqld stop
停止 mysqld: [確定]
卸載舊mysql版本。
[root@www ~]# yum remove mysql mysql-server
已加載插件:fastestmirror, priorities, refresh-packagekit
設置移除進程
Loading mirror speeds from cached hostfile
* base: mirrors.skyshe.cn
* epel: mirrors.hustunique.com
* extras: mirrors.163.com
* rpmforge: mirrors.neusoft.edu.cn
* updates: mirrors.163.com
132 packages excluded due to repository priority protections
解決依賴關系
--> 執行事務檢查
---> Package mysql.i686 0:5.1.73-5.el6_6 will be 刪除
--> 處理依賴關系 mysql = 5.1.73-5.el6_6,它被軟件包 mysql-devel-5.1.73-5.el6_6.i 686 需要
---> Package mysql-server.i686 0:5.1.73-5.el6_6 will be 刪除
--> 執行事務檢查
---> Package mysql-devel.i686 0:5.1.73-5.el6_6 will be 刪除
--> 處理依賴關系 mysql-devel = 5.1.73-5.el6_6,它被軟件包 mysql-embedded-devel-5 .1.73-5.el6_6.i686 需要
--> 執行事務檢查
---> Package mysql-embedded-devel.i686 0:5.1.73-5.el6_6 will be 刪除
--> 完成依賴關系計算依賴關系解決
================================================================================
軟件包 架構 版本 倉庫 大小
================================================================================
正在刪除:
mysql i686 5.1.73-5.el6_6 @updates 2.3 M
mysql-server i686 5.1.73-5.el6_6 @updates 24 M
為依賴而移除:
mysql-devel i686 5.1.73-5.el6_6 @updates 388 k
mysql-embedded-devel i686 5.1.73-5.el6_6 @updates 14 M事務概要
================================================================================
Remove 4 Package(s)Installed size: 41 M
確定嗎?[y/N]:y
下載軟件包:
運行 rpm_check_debug
執行事務測試
事務測試成功
執行事務
正在刪除 : mysql-server-5.1.73-5.el6_6.i686 1/4
warning: /var/log/mysqld.log saved as /var/log/mysqld.log.rpmsave
正在刪除 : mysql-embedded-devel-5.1.73-5.el6_6.i686 2/4
正在刪除 : mysql-devel-5.1.73-5.el6_6.i686 3/4
正在刪除 : mysql-5.1.73-5.el6_6.i686 4/4
Verifying : mysql-5.1.73-5.el6_6.i686 1/4
Verifying : mysql-embedded-devel-5.1.73-5.el6_6.i686 2/4
Verifying : mysql-server-5.1.73-5.el6_6.i686 3/4
Verifying : mysql-devel-5.1.73-5.el6_6.i686 4/4刪除:
mysql.i686 0:5.1.73-5.el6_6 mysql-server.i686 0:5.1.73-5.el6_6作為依賴被刪除:
mysql-devel.i686 0:5.1.73-5.el6_6 mysql-embedded-devel.i686 0:5.1.73-5.el6_6完畢!
[root@www download]# yum remove mysql-embedded mysql-libs
… #刪除中…
如果centos安裝有mysql-client/mysql-devel,同樣需要執行yum刪除。
2、下載mysql5.7,需要先檢查centos的系統位數
[root@www ~]#getconf LONG_BIT
[root@www ~]#getconf WORD_BIT
我這裡兩個顯示都是32,因此應該下載32版本(對應i686)。
到http://dev.mysql.com/downloads/mysql/這個地址下載最新穩定版本,centos對應選擇Red Hat…
[root@www download]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-common-5.7.10-1.el6.i686.rpm
[root@www download]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-libs-5.7.10-1.el6.i686.rpm
[root@www download]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-client-5.7.10-1.el6.i686.rpm
[root@www download]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.10-1.el6.i686.rpm
安裝依賴
[root@www download]# yum install -y libnuma*
分別安裝
[root@www download]# rpm -ivh mysql-community-common-5.7.10-1.el6.i686.rpm
[root@www download]# rpm -ivh mysql-community-libs-5.7.10-1.el6.i686.rpm
[root@www download]# rpm -ivh mysql-community-client-5.7.10-1.el6.i686.rpm
[root@www download]# rpm -ivh mysql-community-server-5.7.10-1.el6.i686.rpm
查看安裝信息
[root@www download]# yum list installed | grep ^mysql
mysql-community-client.i686 5.7.10-1.el6 installed
mysql-community-common.i686 5.7.10-1.el6 installed
mysql-community-libs.i686 5.7.10-1.el6 installed
mysql-community-server.i686 5.7.10-1.el6 installed
最後查看 mysql 版本
[root@www download]# mysql --version
mysql Ver 14.14 Distrib 5.7.10, for Linux (i686) using EditLine wrapper
看來真的已經正確安裝了。
檢查my.cnf
[root@www download]# vim /etc/my.cnf
1 # For advice on how to change settings please see
2 # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
3
4 [mysqld]
5 #
6 # Remove leading # and set to the amount of RAM for the most important data
7 # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
8 # innodb_buffer_pool_size = 128M
9 #
10 # Remove leading # to turn on a very important data integrity option: loggin g
11 # changes to the binary log between backups.
12 # log_bin
13 #
14 # Remove leading # to set options mainly useful for reporting servers.
15 # The server defaults are faster for transactions and fast SELECTs.
16 # Adjust sizes as needed, experiment to find the optimal values.
17 # join_buffer_size = 128M
18 # sort_buffer_size = 2M
19 # read_rnd_buffer_size = 2M
20 datadir=/var/lib/mysql
21 socket=/var/lib/mysql/mysql.sock
22
datadir、socket位置查看
[root@www download]# stat /var/lib/mysql
File: "/var/lib/mysql"
Size: 4096 Blocks: 8 IO Block: 4096 目錄
Device: fd00h/64768d Inode: 2621666 Links: 5
Access: (0751/drwxr-x--x) Uid: ( 27/ mysql) Gid: ( 27/ mysql)
Access: 2015-12-28 01:10:54.855025003 +0800
Modify: 2015-11-30 03:48:49.000000000 +0800
Change: 2015-12-28 00:54:11.506460247 +0800
看來數據還在。
這下可以啟動mysql了吧。
[root@www ~]# /etc/init.d/mysqld start
MySQL Daemon failed to start.
正在啟動 mysqld: [失敗]
提示失敗。先升級mysql配置
[root@www ~]# mysql_upgrade -u root –p
Enter password:
mysql_upgrade: Got error: 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) while connecting to the MySQL server
Upgrade process encountered error and will not continue.
結果報錯,應該是'/var/lib/mysql/mysql.sock' 不存在。先生成一個
[root@www ~]# touch /var/lib/mysql/mysql.sock
還是報錯。
查看mysqld的啟動日志發現從5.1升級到5.7變化很大,報了幾個waring和Error
2015-12-28T13:41:08.287625Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
…
2015-12-28T13:41:09.316911Z 0 [Warning] System table 'plugin' is expected to be transactional.
2015-12-28T13:41:09.318169Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2015-12-28T13:41:09.318285Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key…
2015-12-28T13:41:09.385341Z 0 [Warning] Failed to open optimizer cost constant tables
2015-12-28T13:41:09.386799Z 0 [ERROR] Fatal error: mysql.user table is damaged. Please run mysql_upgrade.
2015-12-28T13:41:09.386944Z 0 [ERROR] Aborting
5.7需要添加幾個系統表。
先以安全模式啟動mysqld守護進程。
[root@www ~]# mysqld_safe start
151228 22:10:42 mysqld_safe Logging to '/var/log/mysqld.log'.
151228 22:10:42 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
151228 22:10:46 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
最後mysqld進程好像沒有啟動成功…
查看3306端口
[root@www ~]# netstat -ano|grep 3306
[root@www ~]#
果然一無所獲。安全進程並未啟動,如錯誤日志所述,基本系統表缺失。初始化之
[root@www ~]# mysqld –initialize
2015-12-28T14:18:49.246041Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-12-28T14:18:49.250859Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2015-12-28T14:18:49.250941Z 0 [ERROR] Aborting
如果查看/etc/init.d/mysqld啟動項應知,mysqld --initialize命令是service mysqld start的一部份,如果 start的時候沒有發現data目錄則安裝之,發現錯誤則報錯…。故,上面的嘗試徒勞。
看來,它檢查到了原5.1的系統表,發現沖突之處。因此,應該將my.cnf下datadir/socket配置指定的存放位置移位。
[mysqld]
datadir=/var/lib/mysql5.7
socket=/var/lib/mysql5.7/mysql.sock#上面socket目錄放在[mysqld]模塊內,那麼[client]也需要指定socket位置,不然會報錯
[client]
socket=/var/lib/mysql5.7/mysql.sock
移動到了mysql5.7目錄。同時,將/etc/init.d/mysqld的47行配置進行修改
[root@www ~]# vim /etc/init.d/mysqld
…
get_mysql_option mysqld datadir "/var/lib/mysql5.7"
使它的datadir指向mysql5.7,根據上下文,mysql.sock的指向也變了,它也存放在mysql5.7目錄下面。
再次執行initialize命令。
[root@www ~]# mysqld –initialize
2015-12-28T14:30:42.853099Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-12-28T14:30:46.950814Z 0 [Warning] InnoDB: New log files created, LSN=45790
2015-12-28T14:30:47.713023Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2015-12-28T14:30:47.950677Z 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: 965094c2-ad6f-11e5-8c8a-001641ad962e.
2015-12-28T14:30:47.999549Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2015-12-28T14:30:48.000932Z 1 [Note] A temporary password is generated for root@localhost: sfW2h2*Y55IS
查看工作目錄是否建立
[root@www ~]# ls /var/lib/mysql5.7
auto.cnf ibdata1 ib_logfile1 performance_schema
ib_buffer_pool ib_logfile0 mysql sys
有關[Warning] TIMESTAMP with implicit DEFAULT value is deprecated.Please use --explicit_defaults_for_timestamp server option (seedocumentation for more details).的警告查看http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_explicit_defaults_for_timestamp,這是個臨時啟動設置,將來會被廢棄,現在提醒你轉向新的mysql非標准sql行為。
再次啟動mysqld安全模式
[root@www ~]# mysqld_safe start
查看端口沒有啟動,提示mysql5.7所在目錄權限
2015-12-28T15:32:06.227936Z 0 [ERROR] InnoDB: ./ib_logfile0 can't be opened in read-write mode.
改變 mysql5.7的所有者和權限為用戶mysql
[root@www ~]# chown -R mysql: /var/lib/mysql5.7
[root@www ~]# chmod -R og+wr /var/lib/mysql5.7
[root@www ~]# ls -laZ /var/lib/mysql5.7drwxrwxrwx mysql mysql ? .
drwxr-xr-x root root ? ..
-rw-rw-rw- mysql mysql ? auto.cnf
-rw-rw-rw- mysql mysql ? ib_buffer_pool
-rw-rw-rw- mysql mysql ? ibdata1
-rw-rw-rw- mysql mysql ? ib_logfile0
-rw-rw-rw- mysql mysql ? ib_logfile1
drwxrwxrw- mysql mysql ? mysql
drwxrwxrw- mysql mysql ? performance_schema
drwxrwxrw- mysql mysql ? sys
再次啟動mysqld_safe start
[root@www ~]# mysqld_safe start
151229 00:40:40 mysqld_safe Logging to '/var/log/mysqld.log'.
151229 00:40:40 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql5.7
151229 00:40:43 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
嗯,已經沒有錯誤了!停止 mysqld_safe
[root@www ~]# mysqld_safe stop
執行啟動 mysqld
[root@www ~]# /etc/init.d/mysqld start
正在啟動 mysqld: [確定]
[root@www ~]# netstat -ano|grep 3306
tcp 0 0 :::3306 :::* LISTEN off (0.00/0/0)
正常啟動。
登陸mysql客戶端
[root@www ~]# mysql -uroot –p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
這個在mysql5.7非常困擾,因為好像從mysql5.6開始,默認新安裝mysql,初始密碼不為空,mysql會隨機生成一個。so,你需要自己重新設置一個。
與mysql5.6 不同, mysql.user下面,沒有password字段:
*************************** 1. row ***************************
Host: localhost
User: root
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
Reload_priv: Y
Shutdown_priv: Y
Process_priv: Y
File_priv: Y
Grant_priv: Y
References_priv: Y
Index_priv: Y
Alter_priv: Y
Show_db_priv: Y
Super_priv: Y
Create_tmp_table_priv: Y
Lock_tables_priv: Y
Execute_priv: Y
Repl_slave_priv: Y
Repl_client_priv: Y
Create_view_priv: Y
Show_view_priv: Y
Create_routine_priv: Y
Alter_routine_priv: Y
Create_user_priv: Y
Event_priv: Y
Trigger_priv: Y
Create_tablespace_priv: Y
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
plugin: mysql_native_password
authentication_string: *D3BFB08382EB0AB95519518E0BFF147C0A4D03E6
password_expired: Y
password_last_changed: 2015-12-28 22:31:03
password_lifetime: NULL
account_locked: N
只有authentication_string,可以看到,初始階段,它不為空。
因為沒法從mysql客戶端進入,因此,只能先關閉mysqld 進程,啟動mysqld_safe,指定--skip-grant-tables。
[root@www ~]# /etc/init.d/mysqld stop
停止 mysqld: [確定]
[root@www ~]# mysqld_safe --skip-grant-tables151229 21:29:14 mysqld_safe Logging to '/var/log/mysqld.log'.
151229 21:29:14 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql5.7
mysqld守護進程打開成功。新打開一個terminal window,進入mysql client。
[root@www ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.10 MySQL Community Server (GPL)Copyright (c) 2000, 2015, 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 -ADatabase changed
mysql> UPDATE mysql.user SET authentication_string=PASSWORD('123456') WHERE User='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)mysql> exit
Bye
在新窗口中退出mysqld_safe進程,
[root@www ~]# ps -A|grep mysql
3758 pts/1 00:00:00 mysqld_safe
3939 pts/1 00:00:00 mysqld
[root@www ~]# kill -9 3758 3939
在mysqld_safe所在窗口(terminal),可以看到mysqld_safe已殺死。
現在嘗試正常開啟mysqld,並進入mysql client。
[root@www ~]# /etc/init.d/mysqld start
正在啟動 mysqld: [確定]
[root@www ~]# mysql -uroot –p
…
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.10Copyright (c) 2000, 2015, 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.
成功。
檢查自啟動項
[root@www download]# chkconfig –list
NetworkManager 0:關閉 1:關閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關閉
…
multipathd 0:關閉 1:關閉 2:關閉 3:關閉 4:關閉 5:關閉 6:關閉
mysqld 0:關閉 1:關閉 2:關閉 3:關閉 4:關閉 5:關閉 6:關閉
netconsole 0:關閉 1:關閉 2:關閉 3:關閉 4:關閉 5:關閉 6:關閉
可見其沒有開啟,故開啟之
[root@www ~]# chkconfig --add mysqld
現在再來看mysqld的啟動項:
…
mysqld 0:關閉 1:關閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關閉
…
已經2 3 4 5級別level啟動(依/ect/init.d/mysqld啟動腳本設定)。
再有選擇地導入之前保存的sql備份(略)。
至此結束。