1 introduction

Recently, in the deployment system environment, the main installation of mysql, Tomcat, JDK, Redis, nginx. Step on a lot of holes, now form a document, avoid later waste of time, this is mysql installation.

2 the installation

2.1 Mysql5.7.20

As of 5.7.18, mysql will also generate my.cnf configuration file, but it is different from the previous default.cnf configuration file, not only location but also content. I was going to upload the resource to CSDN, but the file was too large and limited. So install your own package to solve it. I use a.tar.gz installation package.

2.1.1 Uninstalling Mysql. Usually not, but it’s best to check

rpm -qa | grep mysql
Copy the code

If so, assume the name is mysql-xxx-xx and uninstall it (replace your own name). If you don’t find it, forget it.

rpm -e --nodeps mysql-xxx-xx
Copy the code


2.1.2 Decompressing the package to local. Because it ends in.gz. Unzip the mysql folder without creating it

Tar -xvf mysql-5.7.20-linux-glibc2.5-i686.tar.gz -c /usr/local
Copy the code

Replace the name of your own installation package


2.1.3 Changing the name of the mysql folder

mv mysql-xxx mysql
Copy the code


2.1.4 Creating a User group mysql, create user mysql, add the user to user group mysql, and grant read and write permissions to the user group mysql

groupadd mysql

useradd -r -g mysql mysql

chown -R mysql mysql/

chgrp -R mysql mysql/
Copy the code


2.1.5 Configuration file my.cnf, this is the focus. You can go to etc to find out if my.cnf exists. If not, create a new one by yourself. If it does, there should be some content in it

vim /etc/my.cnf
Copy the code

If it exists, it will have content. If it does not, executing the command above will generate a file. If the content exists, delete it and add the following content. If the content does not exist, add it directly. Then save and exit.

[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
symbolic-links=0

character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# case insensitivelower_case_table_names = 1 sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBST ITUTION max_connections=5000 default-time_zone =From the '+'
Copy the code

Note the previous comments, in fact, is the previous if the existence of the content of the annotations, add their own configuration content, look at the annotations content


2.1.6 Initializing the database has many pitfalls

yum install libaio

cd /var/log/
vim mysqld.log
chmod 777 mysqld.log
chown mysql:mysql mysqld.log

/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US
Copy the code

This step may result in the following error

error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
Copy the code

That’s because the front

Yum installs libnuma. So.1, but installs 32 by default, while DB2 requires 64 bitCopy the code

So we need to uninstall libnuma.so.1 first

yum remove libnuma.so.1

yum -y install numactl.x86_64
Copy the code

After the installation is complete, run the above statement

/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US
Copy the code


2.1.7 Create the mysqld.pid file configured in the my.cnf configuration file

cd /var/run/

mkdir mysqld

chmod 777 mysqld

cd mysqld

vim mysqld.pid

chmod 777 mysqld.pid

chown mysql:mysql mysqld.pid 


Copy the code


2.1.8 Checking the Password Run the server mysql service to log in to mysql

Check the password cat /var/log/mysqld.log Starts the server /usr/local/mysql/support-files/mysql.server start Log in to /usr/local/mysql/bin/mysql -uroot -p Enter the passwordCopy the code

-bash: mysql: command not found -bash: mysql: command not found -bash: mysql: command not found

ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
Copy the code

Then you can use the mysql command.


2.1.9 Changing the Initial Password

set password=password('New password');
flush privileges;
Copy the code

Note that the preceding command can be executed only after you enter mysql


2.2.0 Adding mysql service to startup

cd /usr/local/mysql/support-files

cp mysql.server /etc/init.d/mysqld

chkconfig --add mysqld
Copy the code


2.2.1 Start/stop the service using the service mysqld command

service mysqld start/stop/restart

Copy the code


2.2.2 to avoid every time input the full path of the mysql/usr/local/mysql/bin/mysql, it can be add to the environment variables, in the/etc/profile add two lines of commands

vim /etc/profile

export PATH=/usr/local/mysql/bin:$PATH

source /etc/profile
Copy the code

This allows you to start the client program by typing the mysql command directly into the shell

mysql -uroot -p
Copy the code


2.2.3 Configuring remote Login to the mysql Database In Linux, by default, users other than the local mysql server are not allowed to access the mysql database service. Therefore, root needs to be authorized again. Convenient remote access. mysql> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> select Host,User from user;

+———–+———–+

| Host | User |

+———–+———–+

| % | root |

| localhost | mysql.sys |

| localhost | root |

+———–+———–+

3 rows in set (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON . TO root@’%’ identified by ‘000000’;

Query OK, 0 rows affected (0.00 SEC)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

The ‘000000’ at the end of the authorization statement is the new password of user root of the mysql database.


Ok, this is almost done, finally set up the Mysql security group, you can access the database remotely using tools