Ubuntu11.04 upgrade MySQL5.1 to 5.5

Source: Internet
Author: User
[This article only records the upgrade process, does not discuss the advantages and disadvantages of the two versions, and the current database on this website is relatively simple, there is no stored procedure or anything, so the same method cannot be used in all situations, upgrade is risky, so proceed with caution!] Because the latest MySQL version is still 5.1 In the apt library of Ubuntu, you can only download MySQL for upgrade. Because the two versions are greatly changed, you must first read the upgrade items on the official website upgradingfromfromMySQL5.1to5.5.

[This article only records the upgrade process, does not discuss the advantages and disadvantages of the two versions, and the current database on this website is relatively simple, there is no stored procedure or anything, so the same method cannot be used in all situations, upgrade is risky, so proceed with caution!]

Because the latest MySQL version in the apt library of Ubuntu is still 5.1, you can only download MySQL for upgrade, therefore, you must first read the upgrade items on the official website, upgrading from MySQL 5.1 to 5.5, to ensure that your database and configuration are applicable to the new version.

This article has referred to an English guide A step by step guide to upgrading to MySQL 5.5 but made some adjustments in order and content, in particular, the official website and this English guide both Back Up Files Using mysqldump before the upgrade, and then import the SQL statement after the upgrade, however, this process may take a long time (it may take more than a dozen hours for the database to be re-imported). I upgraded the database directly to the original database file directory, basically in the twinkling of an eye, again, of course, this does not necessarily apply to everyone.

The procedure is as follows:

1.Stop MySQL and back up

Mkdir mysql_5.20.backup

Cd mysql_5.20.backup

Sudo/etc/init. d/mysql stop

All subsequent backup operations are performed in mysql_5.20.backup.

1.1Using mysqldump to back up a database, you can separate the mysql built-in database from the product database

Mysqldump-u user_name-p-databases mysql> mysql_db. SQL
Mysqldump-u user_name-p-databases db_name> db_name. SQL

1.2Back up the MySQL data directory, more backups, more security

Sudo cp-R/var/lib/mysql/mysql-5.1-data.

1.3Back up MySQL configuration files

Sudo cp-r/etc/mysql mysql_5.20.conf

2Install asynchronous io Library

Sudo apt-get install libaio-dev

3.Download the latest MySQL from the official website (we use 64-bit. As of 5.5.16, pay attention to downloading the version of .tar.gz. The tar version is very poor. After decompression, it is all rpm files)

Wget-c "Audio-O mysql-5.5.16-linux2.6-x86_64.tar.gz

4.Copy the downloaded file to/usr/local/, decompress the file, and create a soft link (it is convenient to switch after downloading the new version later)

Sudo cp Co., mysql-5.5.16-linux2.6-x86_64.tar.gz/usr/local
Sudo tar xzvf mysql-5.5.16-linux2.6-x86_64.tar.gz
Sudo ln-s mysql-5.5.16-linux2.6-x86_64 mysql

5.Remove Old MySQL versions

Sudo apt-get remove mysql-server
Sudo apt-get autoremove
Sudo apt-get remove mysql-client
Sudo apt-get autoremove

6.Edit the environment file/etc/environment to make the content as follows:
PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games: /usr/local/mysql/bin"
7.Ensure that the directory of the MySQL socket file exists and can be read and written.

Sudo mkdir/var/run/mysqld/(ignore the error if it already exists)
Sudo chown-R mysql: mysql/var/run/mysqld/

8.Copy a new configuration file

Cd/usr/local/mysql/support-files/
Sudo cp my-large.cnf/etc/mysql/my. cnf

9.Edit the configuration file/etc/mysql/my. cnf and add the following content:

[Mysqld]

User = mysql
Socket =/var/run/mysqld. sock
Port = 3306
Basedir =/usr/local/mysql
Datadir =/var/lib/mysql # different from the English guide here, pointing to the original MySQL database file directory
Tmpdir =/tmp
Log_error =/var/log/mysql/error. log

Note: Make sure that the content of the socket and port fields in [client] and [mysqld] is consistent.

10.Copy the MySQL Startup File

Cd/usr/local/mysql/support-files/
Sudo cp mysql. server/etc/init. d/mysql
Sudo chmod + x/etc/init. d/mysql
Sudo update-rc.d mysql defaults

11.Eliminate the old version of MySQL abuse (different from the English version of the tutorial, because the original configuration file directory and the original database file directory are retained)

Sudo rm-R/usr/lib/mysql

12.Skip grants table to run MySQL

Sudo su # Switch to root, otherwise the mysql account cannot be used in the following command
/Usr/local/mysql/bin/mysqld-skip-grant-tables-user = mysql

13.Open a new terminal

Sudo/usr/local/mysql/bin/mysql_upgrade

If all the logs are OK, it will be okay.
14.Stop the previous mysql process. If ctrl-c cannot stop, kill the process number directly.
15.Start MySQL normally

Sudo/etc/init. d/mysql start

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.