web123456

Uninstalling and installing Mysql under linux 5.7.29

1. First backup the database

Use the mysqldump command,

First enter the bin directory to find the mysqldump command

-E -R  Backup events and stored procedures will be lost without them, remember! ! !

The compressed backup is as follows

mysqldump -h172.20.5.33 -uroot -p 

-E -R  dataassets1  | gzip > /tmp/backup/

If you back up the entire library:

mysqldump -uroot -p --all-databases | gzip > /tmp/

2, stopmysqlService, delete the previously installed mysql uninstall database

Use the following command to check if mysql is installed

rpm -qa|grep -i mysql

Stop the database

service mysql stop

If there is any result, use the rpm -ev command to delete it, with the parameter --nodeps

Example: rpm -ev MySQL-client-5.5.25a-1.rhel5 --nodeps

If there is no result, ignore it

Continue to use the command find / -name mysql

Find MySQL files, then delete rm -rf + path, determine the real path, and prevent other files from being deleted by mistake

After uninstalling /etc/, it will not be deleted, and you can modify the file content during reinstallation.

3. Install mysql5.7.29

Create mysql file

mkdir /usr/local/mysql

Unzip the installation package

tar -xvf mysql-5.7.29-linux-glibc2.12-x86_64.

Move the unzipped content to the directory /usr/local/mysql

mv mysql-5.7.29-linux-glibc2.12-x86_64/* /usr/local/mysql

Enter the folder

cd /usr/local/mysql/

Add group (it already existed before reinstalling, no need to create it)

groupadd mysql

Add user (it has been available before reinstalling, no need to create)

useradd -r -g mysql mysql

Folder permissions are given to musql user group

chown -R mysql:mysql /usr/local/mysql

Create a data file

mkdir /usr/local/mysql/data

Initialize, remember to enter the bin directory, otherwise the file cannot be found error

 /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

---------------If an initialization error occurs, libiao is missing, and if there is no, it is ignored.

--------------yum install libaio

Enter the bin directory and enable SSL

/usr/local/mysql/bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data/

Data file permissions are given to mysql user group

chown -R mysql:mysql /usr/local/mysql/data/

Configuration, add skip-grant-tables in the middle, for the first time to verify login without password.

vi /etc/

[mysqld]

character_set_server=utf8

init_connect='SET NAMES utf8'

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

#Case sensitive: 0-case sensitive, 1-case insensitive

lower_case_table_names = 1

skip-grant-tables

#Don't enable sql strict mode

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

[mysqld_safe]

socket=/tmp/

log-error=/var/log/

pid-file=/usr/local/mysql/data/

Start mysql

service mysql start

If startup fails

1. Query whether mysql exists under /etc//

ll /etc// | grep mysql

I found that there is no mysql file in this directory

2. Query mysql.serverWhere

find / -name

3. Perform the copy operation, /usr/local/mysql/ is my own mysql installation directory.

cp /usr/local/mysql/support-files/ /etc//mysql

-----------Set up the power-on self-start

Replace mysqld to

cp /usr/local/mysql/support-files/  /etc//mysqld

Modify mysqld

vim /etc//mysql

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

Save configuration

chkconfig --add mysqld

4. Modify the root user password

Execute this command to set the soft link to the /usr/bin directory.

ln  -s   /usr/local/mysql/bin/mysql    /usr/bin

mysql -u root -p  , then enter twice to enter mysql

alter user 'root'@'localhost' identified by 'new password';

flush privileges ; 

quit;

If an error is reported: 1290 - The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

Execute it first: flush privileges;

Remote login to mysql

Personal choicenavicatConnect to the database, insert a host value of % data into the user table in the mysql database, then update the password and refresh

update set authentication_string=password('new password') where User='root' and host='%';

flush privileges ;

vi /etc/ 

Comment out #skip-grant-tables

Save and exit

Restart the database

service mysql restart

5. Create a new database

I personally like to create a new database on navicat

6. Restore backup data

gunzip < | mysql -uroot -p dataassets1

7. Create new user, permissions, etc.

CREATE USER 'kettle'@'localhost' IDENTIFIED BY 'password';

CREATE USER 'kettle'@'%' IDENTIFIED BY 'password';

grant all privileges on kettle.* to kettle@localhost;

grant all privileges on kettle.* to kettle@'%';

flush privileges;