1. UseyumMysql installation

 yum -y install mysql-server  Install the latest version of mysql by default
Copy the code

2. Verify that the mysql process is started

  • Check whether the mysql process exists in the current process
ps -el | grep mysqld Mysqld = mysqld
Copy the code

Alternatively, run the following command

systemctl status mysqld  If active (running) is displayed, the startup is successful
Copy the code
  • If it is not enabled, manually enable it
systemctl start mysqld
Copy the code
  • Set automatic startup upon startup
systemctl enable mysqld 
systemctl daemon-reload
Copy the code

3. Log in mysql

  • View the initial login password
vi /var/log/mysqld.log  # Keep your eyes open to use this
Copy the code

Or use the grep command to find out exactly what your initial password is

grep "A temporary password" /var/log/mysqld.log  # View the result as shown below
Copy the code

  • To log in
mysql -uroot -p  Enter the initial password
Copy the code
  • Changing the Initial Password

Other mysql commands cannot be executed after the initial login

show databases; If you want to execute this command, it is not possible
Copy the code

Run the ALTER USER command to change the login password

ALTER USER USER() IDENTIFIED BY '123456'; # change the password of the current login user.
ALTER USER testuser IDENTIFIED BY '123456'; # Basic usage
ALTER USER testuser IDENTIFIED BY '123456' PASSWORD EXPIRE;# Expire the password
ALTER USER testuser IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER; # make password never expire
ALTER USER testuser IDENTIFIED BY '123456' PASSWORD EXPIRE DEFAULT; Set the expiration time by default
ALTER USER testuser IDENTIFIED BY '123456' PASSWORD EXPIRE INTERVAL 90 DAY; # specify expiration interval
Copy the code

The default password policy for mysql is intermediate. The default password policy for mysql is intermediate.

show variables like 'validate_password%';
Copy the code

However, since this is the first login and the password has not been changed, you cannot execute any commands, so you cannot view the specific requirements of the password policy. Just to be brief:

  1. The password must contain at least 8 characters
  2. Contains at least one uppercase letter
  3. There must be at least one digit
  4. At least 1 bit symbol so for now you’ll have to use a slightly more complicated password. Subsequent if Intranet access, need not so trouble, need to be modified, you can refer to this article: www.jianshu.com/p/b437566cc…

4. Create and authorize a user

  • Create a user
# standard command syntax:
create user 'username'@'host' identified by 'password';
# such as:
create user 'shibaoshun'@The '%' identified by 'Iloveyou3000times! ';
Copy the code
  • Authorizing a user
# standard command syntax:
GRANT privileges ON databasename.tablename TO 'username'@'host'
# such as:
GRANT SELECT, INSERT ON test.user TO 'pig'@The '%'; Add, delete, change, check operation permission
GRANT ALL ON *.* TO 'pig'@The '%'; Grant all permissions
GRANT ALL ON databasename.* TO 'pig'@The '%'; # # Specify a database
Copy the code
  • Refresh after authorization is complete
flush privileges
Copy the code

Pay special attention to

The user authorized by the preceding command cannot authorize another user. To enable the user to authorize another user, run the following command:

GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;
Copy the code
  • Revoking user Authorization
REVOKE privilege ON databasename.tablename FROM 'username'@'host';
Copy the code

5. If you encounter any of the following problems while testing remote login:

(1) Mysql does not allow remote login by default, we need to set it, and firewall open port 3306;

firewall-cmd --zone=public --add-port=3306/tcp --permanent Firewall open port
firewall-cmd --reload # reload
Copy the code

(2) If your mysql server is version 8.0+ and you are using mysql client version 8.0+. The following errors are most likely to occur.

Error 2059: Unable to load the authentication plug-in'caching_sha2_password'"ErrorCopy the code

To put it simply, the cause of this problem is that the MySQL client version is too early (5.5.60) (the earlier version of the MySQL client considers the mysql_native_password authentication plug-in, while the older version recognizes the caching_sha2_password plug-in), which causes this error when connecting to the server. The fix is to change the authentication mode of the specified user to the lower version of mysql_native_password (requiring a new password).

  • According to the user account to repair this problem, please refer to the following article chengxuzhilu.com/1684.html to fix this problem
  • Global change: The password authentication mode of all users is changed to the old onemysql_native_password“, you need to modify the configuration file. Please refer to the following links:Blog.csdn.net/airt_xiang/…

6. Set the default encoding to UTF-8

The default encoding format for mysql8.0+ is UTF8MB4, which is compatible with 4-bit Chinese characters. The difference between this encoding and UTF8 can be seen in the following article:

< never use UTf8 in MySQL, use UTf8mb4 instead >

Blog.csdn.net/u010584271/…

<utf8 and UTf8mb4 difference >

www.cnblogs.com/amou/p/9063…

If you still need to change the encoding format, perform the following operations:

Modify the /etc/my.cnf configuration file and add the encoding configuration under [mysqld] as follows:

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
Copy the code

Restart the mysql service

systemctl restart mysqld
Copy the code

After restart, check the encoding of write mysql at this time

show variables like '%character%';
Copy the code

7. Uninstall mysql

Uninstall mysql in Linux Uninstall mysql in Linux

  • Find the installed version of myslq:
The RPM - qa | grep mysql (pay attention to the case, if not mysql in mysql)Copy the code
  • Unmount the package name found in the search
rpm -e-- nodeps mysql-5.0.77-4.el5_4.2 (nodeps indicates forcible deletion)Copy the code

8. Check the mysql installation path

  • View the file installation path

Since the software is installed in more than one place, so first look at all the paths (addresses) of the file installation.

Mysql is used as an example. For example, if I install mysql, but I do not know where the files are installed, and in which folder, I can use the following command to check the path of all files:

whereis mysql
Copy the code

If you have mysql installed, it will show you where the file was installed, like mine (installation address may vary).

mysql: /usr/bin/mysql /usr/lib/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

  • Querying the path of the running file (Folder address)

If you want to query the location of the file’s run file, you can use the following command:

which mysql
Copy the code

Terminal display:

/usr/bin/mysql

9. View or edit the mysql configuration file

First, let’s see where your mysql is, using which

which mysql
Copy the code

I’m going to show you the directory like mine is this one down here

/usr/bin/mysql
Copy the code

Now you can see where the configuration file is with some commands for this directory, like

/usr/bin/mysql --verbose --help | grep -A 1 'Default options'
Copy the code

And then there will be some information like mine

Default options are read from the following files in the given order:
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf 
Copy the code

The meaning of this information is: the server is first reads/etc/mysql/my CNF file, if a file does not exist before continued to read/etc/my. The CNF file, if there is no will to read ~ /. My. CNF file. /etc/ mysql.cnf/mysql.cnf/mysql.cnf/mysql.cnf/mysql.cnf