Steps for installing MySQL _ MySQL

Source: Internet
Author: User
Install MySQL

Suppose you put all the necessary source code or packages under/tmp. If you download an RPM package, it is relatively simple; if you download a binary package (you do not have an rpm program or you want to customize it), it will be a little more troublesome.

RPM Package installation

You must be the root user to use the rpm installer. the installation process is as follows:

$ Cd/tmp

$ Su

# Rpm-Uvh MySQL * (install all MySQL-related packages)

This will install all three MySQL packages you downloaded. If your system is RedHat Linux, we recommend that you use the RPM installation method, because all the work is done by the rpm program.

Source code installation

Compared with RPM installation, installing with binary source code is a little troublesome. However, you can customize the installation parameters in the installation script, instead of installing the default one in rpm mode.

Install binary source code

If you download binary source code, its name is similar to: mysql-3.22.21-pc-linux-gnu-i686.tar.gz. You must be the root user and decompress the package to the/usr/local directory. the procedure is as follows:

$ Cd/usr/local

$ Su

# Tar-zxvf/tmp/mysql-3.22.21-pc-linux-gnu-i686.tar.gz

After all files are decompressed, a directory named mysql-3.22.21-pc-linux-gnu-i686 will be created. Mysql-3.22.21-pc-linux-gnu-i686 so long ):

# Ln-s mysql-3.22.21-pc-linux-gnu-i686 mysql

If a new version of MySQL is available in the future, you can extract the source code to the new path, and then just create a symbolic link. This is very convenient and data is more secure.

Create a MySQL User

Now we will create a user account that can run the MySQL daemon, and all MySQL files are owned by this account. Use the Linuxconf or useradd command to add an account named mysql. before adding the account, make sure that no one has registered the account, you must temporarily disable the login function (however, this step is generally skipped when no one else logs in to debug the machine)

Prepare for MySQL

First, let's change the ownership of the MySQL directory and file to the mysql User and root group:

# Cd/usr/local

# Chown-R mysql: root mysql-3.22.21-pc-linux-gnu-i686 mysql

Then run a small script program to create the initialized MySQL database. Please complete this task as a mysql User, which is the only opportunity for us to directly use this account.

# Su mysql

$ Cd mysql

$ Scripts/mysql_install_db

$ Exit

If no error information is displayed, you can.

Automatically run MySQL

In the MySQL binary package, there is a startup script program named myslq. server. Copy it to the/etc/rc. d/init. d Directory:

# Cd/etc/rc. d/init. d

# Cp/usr/local/mysql/support-files/mysql. server mysql

Change its attribute to "x" (executable, executable)

# Chmod + x mysql

Finally, run chkconfig to add MySQL to the startup service group of your system.

#/Sbin/chkconfig -- del mysql

#/Sbin/chkconfig -- add mysql

Test MySQL

MySQL has a simple database example test, and its internal database keeps monitoring of permissions and accounts, so run mysql first to see if it can work.

Start MySQL first:

#/Etc/rc. d/init. d/mysql start

If everything is normal, you will see the following information:

Starting mysqld daemon with databases from/var/lib/mysql

If you install the RPM package, most of the programs are installed in/usr/local/mysql/bin. Run the client program in this directory:

# Mysql

Then you can see the following information on the screen:

Welcome to the MySQL monitor. Commands end with; or g.

Your MySQL connection id is 2 to server version: 3.22.21

Type 'HELP' for help.


Then, use the show databases command to list the installed databases:

Mysql> show databases;

You can see:

+ ---------- +

| Database |

+ ---------- +

| Mysql |

| Test |

+ ---------- +

2 rows in set (0.00 sec)

If everything is normal, it means MySQL can work completely! Congratulations! To exit the program, enter exit.

Mysql> exit;


Change administrator password

After everything is normal, the first thing to do is to change the administrator password. You can run mysqladmin (note that this command is not necessarily in your path, so it is best to directly execute it in the directory of this command ):

# Mysqladmin-u root password newpassword

This command changes the password of the root user to newpassword. Of course, you can change the password to another one, because it is easy to crack.

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: 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.