Detailed description of the formal installation of the MySQL database

Source: Internet
Author: User

We all know that after the MySQL database is installed in the supervisor, we can officially install it. We will describe the actual operation steps in a hypothetical way, assuming that all necessary source code or packages are placed under/tmp. If you download the RPM package, it is relatively simple;

If you download a Binary Package and you do not have an rpm program or 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:

 
 
  1. $ Cd/tmp
  2. $ Su
  3. # 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 the Binary source code, its name is similar to: Installing 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:

 
 
  1. $ cd /usr/local  
  2. $ su  
  3. # 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. We make a symbolic link for this directory and give it a more friendly name MySQL to avoid calling the MySQL-3.22.21-pc-linux-gnu-i686 so long ):

 
 
  1. # 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 used to debug the machine without logging on to other users)

Prepare for MySQL

First, let's change the ownership of the MySQL directory and file to the supervisor to install the MySQL user and root group:

 
 
  1. # cd /usr/local  
  2. # 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.

 
 
  1. # su MySQL  
  2. $ cd MySQL  
  3. $ scripts/MySQL_install_db  
  4. $ exit 

If no error information is displayed, you can.

Automatic RunningMySQL

In the MySQL Binary Package, there is a STARTUP script program named myslq. server. Copy it to the/etc/rc. d/init. d directory:

 
 
  1. # cd /etc/rc.d/init.d  
  2. # cp /usr/local/mysql/support-files/mysql.server mysql 

Change its attribute to "x" executable, which can be executed)

 
 
  1. # chmod +x mysql 

Finally, run chkconfig to add MySQL to the startup Service Group of your system.

 
 
  1. # /sbin/chkconfig --del mysql  
  2. # /sbin/chkconfig --add mysql 

Test MySQL

MySQL has a simple database example "test" installed in mysql. In addition, its internal database keeps monitoring of permissions and accounts. Therefore, run MySQL to check whether it can work.

Start MySQL first:

 
 
  1. # /etc/rc.d/init.d/mysql start 

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

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

 
 
  1. # mysql 

Then you can see the following information on the screen:

 
 
  1. Welcome to the MySQL monitor. Commands end with ; or \g.  
  2. Your MySQL connection id is 2 to server version: 3.22.21  
  3. Type 'help' for help.  
  4. mysql> 

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

 
 
  1. mysql> show databases; 

You can see:

 
 
  1. +----------+  
  2. | Database |  
  3. +----------+  
  4. | mysql |  
  5. | test |  
  6. +----------+  
  7. 2 rows in set (0.00 sec)  

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

 
 
  1. mysql> exit;  
  2. Bye  

Change administrator password

After everything is normal, the first thing to do is to change the administrator password. You can run the dig command to install 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 ):

 
 
  1. # 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.

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.