Linux install mysql (fill in the pit version)

Before installation, first check whether the system has installed mysql:

rpm -qa | grep mysql

If it is already installed, you can choose to uninstall it through the following command:

rpm -e mysql // normal delete mode

rpm -e --nodeps mysql // Powerful delete mode, if you use the above command to delete other files that are dependent on it, you can use this command to delete it forcefully

Install Mysql

Tools: CentOS 7 64-bit, Mysql5.7

1 Download the binary installation package compiled by mysql from the official website

Choose a 64-bit system to download Linux-Generic (glibc 2.5) (x86, 64-bit).

2 Unzip the installation package

Enter the directory where the installation package is located, and unzip the installation package:

tar -zxvf mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz

3 Copy the decompressed mysql directory to the local software directory of the system

Note: Do not add / at the end of the directory

mv mysql-5.7.10-linux-glibc2.5-x86_64 /usr/local/mysql

4 Add system mysql group and mysql user

Execute commands: groupadd mysql and useradd -r -g mysql mysql

5 Install the database

5.1 Create a data directory and grant permissions:

mkdir -p /data/mysql

chown mysql:mysql -R /data/mysql

5.2 Configure my.cnf:

vim /etc/my.cnf

The content is as follows:

[mysqld]

bind-address=0.0.0.0

port=3306

user=mysql

basedir=/usr/local/mysql

datadir=/data/mysql

socket=/tmp/mysql.sock

log-error=/data/mysql/mysql.err

pid-file=/data/mysql/mysql.pid

#character config

character_set_server=utf8mb4

symbolic-links=0

explicit_defaults_for_timestamp=true

 

5.3 Initialize the database

Enter the bin directory of mysql: cd /usr/local/mysql/bin

initialization

./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize

5.4 Start mysql service at boot

Put the startup script in the boot initialization directory:

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

Grant executable permissions: chmod +x /etc/init.d/mysql

Add as a service: chkconfig --add mysql

View the list of services: chkconfig --list mysql

Seeing 3, 4, and 5 status as on or on means success. If it is off or off, execute it: chkconfig --level 345 mysqld on

5.5 Start

Start mysql

service mysql start

ps -ef|grep mysql see that the mysql service shows that the startup is successful, as shown in the figure

This shows that mysql has been installed successfully!

5.6 Change password

Modify the mysql password below, first log in to mysql, the initial password is empty, if you cannot successfully log in:

Then, first stop the service: /etc/init.d/mysql stop

Then enter the bin directory under the mysql installation directory and execute:

./mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

Log in to mysql -u root -p again, you can log in. As shown below

After entering, execute: mysql> flush PRIVILEGES;

Reset password: mysql> alter user'root'@'localhost' identified by '1234567';

Execute mysql>fulsh tables; to exit. You can use the new password when you log in again.

5.7 mysql allows remote access

Turn off the server firewall first.

Log in to mysql, check the host field of the user table in the mysql library

In the Host field, localhost means that only local access is allowed. To realize remote connection, you need to change the host of the root user to% to allow any host to access. Then use the command mysql> flush privileges; to make this modification effective immediately.

Connect remotely again, success!