Install Mysql manually in Linux

Source: Internet
Author: User
The following is a description of the manual installation of the mysql binary distribution from the MySQL official documentation: 1. The installation must be executed to install and use the basic MySQL binary distribution command: shellgroupaddmysqlshelluseradd-gmysqlmysqlshellcdusrlocalshellgunzippathtomysql-VERSION-OS.ta

The following is an excerpt from the mysql documentation about manual installation of the MySQL binary distribution: 1. The installation must be executed to install and use the basic MySQL binary distribution command: shell groupadd mysql shell useradd-g mysql shell cd/usr/local shell gunzip/path/to/mysql-VERSION-OS. ta

The following is an excerpt from the mysql documentation about manual installation of the MySQL binary distribution edition:

I. Installation

You must run the following basic commands to install and use MySQL binary distribution:

Shell> groupadd mysql

Shell> useradd-g mysql

Shell> cd/usr/local

Shell> gunzip </path/to/mysql-VERSION-OS .tar.gz | tar xvf-

Shell> ln-s full-path-to-mysql-VERSION-OS mysql

Shell> cd mysql

Shell> scripts/mysql_install_db -- user = mysql

Shell> chown-R root.

Shell> chown-R mysql data

Shell> chgrp-R mysql.

Shell> bin/mysqld_safe -- user = mysql &


Note: No password is set for the MySQL account during this process. After completing the following process, continue to "configure and test after installation" in section 2.9 ".

The following describes how to install the binary distribution:

1. Add a logon user and group for mysqld:

2.Shell> groupadd mysql

3.Shell> useradd-g mysql

These commands will add MySQL groups and MySQL users. In Unix of different versions, the syntax of useradd and groupadd may be slightly different. It can also be called adduser and addgroup. You may name these users and groups out of mysql. If so, replace it with the corresponding name in the following steps.

4. Select a directory where you want to unbind the package and go to the directory. In the following example, we will release the package under "/usr/local" (therefore, the following description assumes that you have the permission to create files and directories in "/usr/local, if the directory is protected, you need to install it as root ).

5. shell> cd/usr/local

6. Obtain a distribution file from one of the sites listed in section 2.1.3 "How To Get MySQL. For a given version, the binary distribution of all platforms is built from the same MySQL source distribution version.

7. The package release version will create an installation directory. Then generate a symbolic link to the directory:

8.Shell> gunzip </path/to/mysql-VERSION-OS .tar.gz | tar xvf-

9.Shell> ln-s full-path-to-mysql-VERSION-OS mysql

Run the tar command to create the mysql-VERSION-OS directory. Ln command to generate a symbolic link to this directory. This makes it easier to specify the installation directory as/usr/local/mysql. If you use GNU tar, you no longer need gunzip. You can use the following command to replace the first line to unpack and extract the distribution version:

Shell> tar zxvf/path/to/mysql-VERSION-OS.tar.gz

10. Enter the installation directory:

11. shell> cd mysql

You will find several files and subdirectories in the mysql directory. The most important for installation is the "bin" and "scripts" subdirectories. The bin directory contains the client program and server. You should add the full PATH of this directory to the path environment variable so that shell can find the MySQL program correctly. See Appendix F: environment variables. The scripts directory contains the mysql_install_db script, which is used to initialize the mysql database authorization table, where server access is allowed.

12. If MySQL has not been installed, you must create a MySQL authorization table.

13.Shell> scripts/mysql_install_db -- user = mysql

If you use root to run the command, you should use the -- user option. The option value should be the same as the login account you created for the running server in the first step. If you use this user to log on to run the command, you can omit the -- user option. After creating or upgrading the authorization table, you need to manually restart the server.

14. Change the binary ownership of the program to root, and change the ownership of the data directory to the user who runs mysqld. If you are in the installation directory (/usr/local/mysql), the command should be:

15.Shell> chown-R root.

16.Shell> chown-R mysql data

17.Shell> chgrp-R mysql.

The first command changes all attributes of the file to the root user. The second command changes all the attributes of the data directory to the mysql user. The third command changes the group attribute to the mysql group.

18. If you like to automatically start MySQL when booting the machine, you can copy the support-files/mysql. server File to a place where the system has a Startup File. For more information, see support-files/mysql. server script and section 2.9.2.2, "Automatically Start and Stop MySQL.

19. If the DBI and DBD: mysql Perl modules are installed, you can use the bin/mysql_setpermission script to add a new account. For instructions, see section 2.13, "notes for installing Perl ".


20. If you want to use mysqlaccess and have a MySQL distribution version in a non-standard location, you must change the location where mysqlaccess expects to find the mysql client. Edit the "bin/mysqlaccess" script, which contains about 18th rows and looks for rows similar to the following:

21. MYSQL = '/usr/local/bin/mysql'; # path to mysql executable

Change the path to reflect the location where mysql is actually stored on your system. If you do not run mysqlaccess, you will encounter a broken pipe error. After everything is unwrapped and installed, you should initialize and test your distribution version. Run the following command to start the MySQL server:

Shell> bin/mysqld_safe -- user = mysql &

For more information about mysqld_safe, see section 5.1.3, "mysqld_safe: MySQL server startup script ".

Note: The account in the MySQL authorization table does not have a password. After starting the server, use the instructions in section 2.9, "setup and test after installation" to set the password.

Ii. Set Automatic startup

For manually installed binary distribution versions, we can find a script named MySQL. server in the support-files directory under the mysql installation directory. We need to copy the script to the/etc/init. d directory, change it to mysql, and set the file to be executable.


Shell> cp mysql. server/etc/init. d/mysql


Shell> chmod + x/etc/init. d/mysql


The following work may vary depending on the Linux version. For some systems, we can use chkconfig -- add mysql to register the Startup Program. For Ubuntu systems, we should use the ubuntu built-in update-rc.d solution (chkconfig for linux comes, the latest Ubuntu version does not contain this command)


Shell> sudo update-rc.d mysql ults


After the above settings, mysql can automatically run in ubuntu.

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.