Installation, configuration and application of mysql (5.7) under CentOs7

There are some differences from the previous version of mysql. Now write down the complete process, which may be useful for novices.

The installation described in this article is to use the general binary compressed package (linux - Generic) to install by decompression, which is equivalent to a green installation.
 
1. Download the universal installation binary package
 
First download the mysql installation package: open http://dev.mysql.com/downloads/mysql/
Select linux - Generic and select under it
Linux - Generic (glibc 2.5) (x86, 64-bit), Compressed TAR Archive
to download. You can download it to a temporary directory first, and after decompression, you will get two packages:
mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz 
mysql-test-5.7.11-linux-glibc2.5-x86_64.tar.gz
All you need is the mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz package.
 
2. Create users and directories
 
Create user mysql, group mysql. Later, mysql will use this user to run (note that this is also the default user in the mysql startup script, so it is best not to change the name).
#groupadd mysql
#useradd -r -g mysql mysql
(Use the -r parameter to indicate that the mysql user is a system user and cannot log in)
 
Create a directory /work/program, and mysql will be installed in this directory later.
#mkdir /work/program
 
3. Installation
 
【Decompression】
Unzip the mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz obtained earlier to the /work/program directory
#tar zxvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz -C /work/program
 
At this time, the directory name obtained under the program is very long. If you do not want to change the name, you can establish a connection:
#ln -s mysql-5.7.11-linux-glibc2.5-x86_64 mysql
After that, you can use /work/program/mysql to find the mysql installation directory
 
Note that if there is no data directory in the mysql directory, create one manually.
 
[Directory permission settings]
Set mysql and all the directory owners and groups under it to mysql:
#cd /work/program/mysql
#chown mysql:mysql -R .
 
【initialization】
#/work/program/mysql/bin/mysqld --initialize --user=mysql --datadir=/work/program/mysql/data --basedir=/work/program/mysql
Notice:
1. There is no data directory after decompression, it needs to be created manually (see above);
2. mysql5.7 is different from the previous version, many of the data are this command
...../scripts/mysql_install_db --user=mysql
 And version 5.7 doesn't have this at all.
 
After the initialization is successful, the following information appears:
201x-xx-xxT07:10:13.583130Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
201x-xx-xx T07:10:13.976219Z 0 [Warning] InnoDB: New log files created, LSN=45790
201x-xx-xx T07:10:14.085666Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
201x-xx-xx T07:10:14.161899Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 1fa941f9-effd-11e5-b67d-000c2958cdc8.
201x-xx-xx T07:10:14.165534Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
201x-xx-xx T07:10:14.168555Z 1 [Note] A temporary password is generated for root@localhost: q1SLew5T_6K,
 
Pay attention to the last line, which is also different from the previous version. It gives root an initial password, which will be used when logging in later.
 
【Configuration】
Rename my-default.cnf under mysql/support-files to my.cnf, copy it to /etc (or test it under {mysql}, and then make a soft link to /etc):
#cp /work/program/mysql/support-files/my-default.cnf /etc/my.cnf
Key configuration in my.cnf:
[mysqld]
basedir = /work/program/mysql
datadir = /work/program/mysql/data
port = 3306
socket = /work/program/mysql/tmp/mysql.sock
 
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
 
Note that the tmp directory does not exist, please create it.
 
If you don't copy my.cnf to /etc, it will appear when running:
mysqld: Can't change dir to '/usr/local/mysql/data/' (Errcode: 2 - No such file or directory)
Such an error message indicates that it did not find the configuration in my.cnf; instead, it went to the default installation location when the program was compiled: /usr/local/mysql
 
4. Operation
 
【Run the server program】
#{mysql}/bin/mysqld_safe&
Note: --user=mysql has been set by default in this startup script; adding & at the end of the script means setting this process as a background process, the difference is that input bg in the console, the current process can be transferred to the background, and the current shell can proceed other operations.
[stop mysql]
{mysql}/bin/mysqladmin -uroot -p
(Note that the root at this time refers to the root user of mysql)
 
Five, set up mysql to run as a service and start at boot
 
Copy {mysql}/support-files/mysql.server to /etc/init.d/mysql and set running permissions
 
#cp mysql.server /etc/init.d/mysql
#chmod +x /etc/init.d/mysql
 
Register mysql as a startup service
#chkconfig --add mysql
 
Of course, you can also manually open and close the service:
#/etc/init.d/mysql start
#/etc/init.d/mysql stop
 
 
6. Client connection test
 
#{mysql}/bin/mysql -uroot -p
At this time, a password is required, which is the password generated during the previous initialization.
At this time, if there is an error when connecting to the service:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Then you need to add in my.cnf:
[client]
socket = /work/program/mysql/tmp/mysql.sock
 
After connecting, before doing any operation, mysql requires the root password to be changed before the operation can be performed.
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by 'xxxxxxx';
 
7. TIPS
 
[Check if mysql is running]
ps -ef | grep mysqld
netstat -lnp | grep -i mysql
 
[The order of reading the configuration file my.cnf when mysql starts]
You can run the following command to view:
./bin/mysqld --verbose --help |more
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
It can be seen that the configuration file my.cnf can be read from the above directory at startup. If the current my.cnf file is not located in the above location, you must test it or make a link.
 
【end】

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327007299&siteId=291194637
Recommended