CentOS 7 to install MySQL 5.7.11 for Linux Generic binary version in the command line tutorial _mysql

Source: Internet
Author: User
Tags documentation centos mysql database

The latest version of MySQL is 5.7.11, which provides a specific distribution installation package (such as. rpm) and a binary generic installation package (. tar.gz) under Linux. In general, many projects tend to adopt a binary common installation package form for installation configuration, customization is very convenient. But in the installation process found, in fact, the official installation of the instructions file is too simple, and there are problems in the parameters, in accordance with the implementation of the MySQL service to start the error, look for some data and repeated tests, they summed up a set of practical installation configuration process, specific as follows:

1, download the MySQL for Linux Generic binary version of the installation package (. tar.gz), here in the 5.7.11 version as an example.

2, I am generally accustomed to install MySQL to the/opt directory, so I will be the MySQL installation package files copied to the/OPT directory, switch to the root account after the execution of the following command:

# TAR-ZXVF mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
# ln-s mysql-5.7.11-linux-glibc2.5-x86_64 MySQL 
# CD Mysql

The establishment of a MySQL soft connection, is to facilitate later configuration and operation.

3, 5.7.11 version of the Universal binary installation package after the extraction of the MySQL directory, the internal does not contain data files stored in the directory, so you need to create a separate subdirectory for the data file, such as the name of information, in the second step after the command (to ensure that the/opt/mysql directory), Continue with the following command:

# groupadd MySQL #
useradd-r-G mysql-s/bin/false MySQL
# mkdir data # chown-r
root:root.
# bin/mysqld--initialize--user=mysql--basedir=/opt/mysql--datadir=/opt/mysql/data
# Bin/mysql_ssl_rsa_setup- -datadir=/opt/mysql/data

In particular, according to the official documentation, the MySQL initialization uses the mysqld--initialize command, starting with the version 5.7.6, and no longer uses the mysql_install_db command. However, the Mysqld--initialize command given in the official documentation does not give--basedir and--datadir parameters because it uses the/ETC/MY.CNF profile by default. Some Linux distributions may default to generate this MySQL profile during installation and are saved in the/ETC directory, while the Basedir, DataDir in the default profile are annotated with no actual content, so mysqld actually don't know the current basedir, DataDir is specific to which directory. So here we can specify our custom directory by command-line arguments. Include the Mysql_ssl_rsa_setup command to specify the DataDir directory, because the key files required by the database are also stored with the data file, all in the DataDir directory.

4, the above work is completed, first do not panic start the database service, at this time also to create a MySQL service configuration file MY.CNF. This file can be found in a/opt/mysql/support-files subdirectory called MY-DEFAULT.CNF Configuration sample file, and then copy one out, renamed MY.CNF and put it under/opt/mysql. According to the rules of MySQL, its configuration file must be named MY.CNF, read the order of first attempt to read/etc/my.cnf, if not exist then read the Basedir directory my.cnf, if the system environment variable does not basedir, Attempt to read the MY.CNF in the current directory where the service was started, this is/opt/mysql/my.cnf this case, or if it does not exist, read the. mysql/my.cnf in the current user's home directory. (see the official document for confirmation, not to be remembered). So, we just need to make sure that there is a my.cnf under the/opt/mysql, modify the contents as follows:

Basedir =/opt/mysql
datadir =/opt/mysql/data
log-error =/var/log/mysql-error.log

The rest is unchanged. According to the official documentation, LOG-ERROR is used to specify the path of the running information log file after the service starts, and the running information includes logs of the type Notice, error, and so on.

5. After the configuration file modification is saved, you can start the service, make sure the current directory is/opt/mysql, and then run the following command:

# Bin/msyqld_safe--user=mysql &

Then the service can be started normally. You can also use the command netstat-na-t to see if the MySQL service port 3306 is already listening and, if so, the service is starting up properly. Of course, you can also view the contents of the log file to determine that we are here because the log file specified in the configuration file is/var/log/mysql-error.log, so view the file.

6, in the local login MySQL service, starting from the 5.7.10 version does not allow the root null password login. In fact, after performing mysqld--initialize system will generate an initialization password for root, and in the screen standard output display, this to remember! This password is used for the first time to change the password, which assumes that the system generated initialization password is XXXXXX, and the command is as follows:

# Bin/mysql--user=root--password=xxxxxx

This allows you to log on to the MySQL server.

7. After login, the system requires that the password of the root account be modified, and the MySQL command is as follows:

Mysql> set Password=password (' 1234 ');

This will change the root account to 1234.

8, in order to secure under Linux, the default is not to allow MySQL server outside the machine to access the MySQL database service, so the need to authorize the root account. Convenient for other machines to remotely access the MySQL server, the MySQL command is as follows:

Mysql> grant all privileges in *.* to root@ '% ' identified by ' 1234 ';
mysql> flush Privileges;

This allows remote logins from other machines with the root account to the MySQL server, you can use the following MySQL command to verify:

mysql> use MySQL;
Mysql> select Host,user from user;
+-----------+-----------+
| host | user |
+-----------+-----------+
|% | root |
| localhost | Mysql.sys |
| localhost | Root |
+-----------+-----------+
3 rows in Set (0.00 sec)

Proof that a record of root remote logins has been added to the system table user.

9, to add how to stop the MySQL service command:

# mysqladmin--user=root--password shutdown

Here root is the MySQL database root, not the operating system account, do not confuse this, the command will prompt input MySQL root password, the correct words will stop the MySQL service.

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.