Upgrade mysql under centOS 6.5, from 5.1 to 5.7

1. Backup the database and upgrade MySQL usually without losing data, but to be on the safe side, we need to do this step. input the command:

mysqldump -u xxx -h xxx -P 3306 -p --all-databases > databases.sql

2. Stop the MySQL service and enter the command:

    service mysqld stop

3. To uninstall the old version of MySQL, enter the command:

    yum remove mysql mysql-*

During the execution, you will be asked whether to remove, enter "Y" at this time

View installed software:

rpm -qa¦grep mysql

Uninstall mysql:

yum remove mysql mysql-server mysql-libs compat-mysql51

4. After the removal command is executed, you can check whether there is any remaining mysql and enter the command:

    yum list installed | grep mysql

If there is, you can enter the command to delete:

    yum remove mysql-libs

5. Download and install the latest rpm file.

This step depends on what files you need, what I installed is: mysql57-community-release-el6-7.noarch.rpm (if you get this file in advance, you can use yum localinstall mysql57-community-release-el6- 7.noarch.rpm from local installation)

rpm -Uvh http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm

6. Install MySQL and enter the command (in the process, ask if yes, go all the way to y):

    yum install mysql-community-server

7. After the installation is complete, enter the command to check the MySQL version number:

    mysql -V

8. Start MySQL and enter the command:

    service mysqld start

The first startup is slow because it will initialize by itself, just wait patiently.

If the startup fails and the message "MySQL Daemon failed to start" is displayed, you can try to initialize mysql first and enter the command: mysqld --initialize.

If the initialization prompts:

    2015-12-22T07:49:45.386095Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2015-12-22T07:49:45.388125Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
    2015-12-22T07:49:45.388153Z 0 [ERROR] Aborting

Indicates that the data folder has been created, delete it directly, let mysql create it by itself, enter the command: rm -rf /var/lib/mysql

After deleting, note: Then you don't need to initialize again, start mysql directly, it will initialize by itself, enter the command:

    service mysqld start

9. After entering mysql, the first thing is to ask you to change the default password. After mysql 5.7, the system automatically generates a random password. When I operate, I don't log in, switch mysql to safe mode to start, and modify it myself (to change the password in safe mode, see another article: MySQL forgot password, or: root Password reset error: mysqladmin: connect to server at 'localhost' failed solution).

    [root@c12 mysql57]# ./bin/mysql -u root -p

    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

    mysql> alter user root identified by 'root';
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

Using mysqladmin can finally change

    [root@c12 mysql57]# ./bin/mysqladmin -u root -p password
    Enter password: 
    New password: 
    Confirm new password: 
    Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

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

10. Set mysql to start at boot

    chkconfig --list             显示服务列表

If you see the mysqld service, and 3, 4, and 5 are all on, it is successful, if it is off, type

    chkconfig --level 345 mysqld on

reboot reboot computer

netstat -na | grep 3306, if you see a monitor, the service is started. You can also use: service mysqld status to see the status

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325017722&siteId=291194637