CentOS installation mysql8.0

(1) Method 1, online installation

1. Configure yum source

1. Download the mysql source installation package

Download the YUM source rpm installation package from the MySQL official website: http://dev.mysql.com/downloads/repo/yum/
insert image description here
insert image description here
Copy the download link: https://dev.mysql.com/get/mysql80-community-release-el7 -3.noarch.rpm
This download directory is: /home/directory, so enter: cd /home
to execute the download command:

wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

2. Install mysql source

After the download is complete, use the following command to install the source:

yum localinstall mysql80-community-release-el7-3.noarch.rpm

3. Check whether the installation is successful

Use the command to check whether the installation is successful. If it is successful, the following figure will be displayed.

yum repolist enabled | grep "mysql.*-community.*"

insert image description here

If unsuccessful: Solve the error of installing MySQL under CentOS8: no match: mysql-community-server
insert image description here
execute the following command:

rpm -ivh mysql80-community-release-el8-1.noarch.rpm

insert image description here
Execute again to complete the installation
insert image description here

Two, install mysql

Use the command directly:

yum install mysql-community-server 

mysql8.0 is case-sensitive, add lower_case_table_names=1, must be set after installation
Modify /etc/my.cnf Add lower_case_table_names=1
in [mysqld] #Maximum number of connections max_connections=200


3. Start the mysql service

1. start

systemctl start mysqld  

or

service mysqld start

2. Check the startup status

systemctl status mysqld 

or

service mysqld status

3. Restart

systemctl restart mysqld

or

service mysql restart

4. Set the boot to start

systemctl enable mysqld
systemctl daemon-reload

4. Configuration and some commands

1. Modify the login password

After the mysql installation is complete, a default password is generated for root in the /var/log/mysqld.log file. Find the root default password in the following way, and then log in to mysql to modify it:
grep 'temporary password' /var/log/mysqld.log
The local MySQL client logs in to
mysql -uroot -p
The password is queried in the previous step. Enter and press Enter.
Then change the password:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'XXXXX111';

2. Add a remote login user

Create a new user
create user 'root'@'%' identified by 'sta';
authorize
grant all privileges on . to 'root'@'%' with grant option;
refresh privileges
flush privileges;
since 8.0 uses caching_sha2_password encryption password, before Version tools may not be able to connect, change the encryption method
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'sta';

3. Modify the default encoding method

The default encoding method of mysql8.0 is utf8mb4, so there is no need to modify it when using it. You can use the following command to view it:
SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%';
if you need to modify other encoding methods, there are many ways, The following are examples only.
For example, you need to change it to utf8mb4, you can use the following method:
modify the mysql configuration file my.cnf (windows is my.ini)
my.cnf is generally located in /etc/my.cnf. After finding it, please add the following content in the following three parts:

[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect=‘SET NAMES utf8mb4’

Just restart mysql.
It doesn't matter what collation_connection, collation_database, collation_server are. But must ensure that the following variables must be utf8mb4. :

character_set_client (character set used by client source data)
character_set_connection (connection layer character set)
character_set_database (default character set of the currently selected database)
character_set_results (query result character set)
character_set_server (default internal operation character set)

Among the database connection parameters:
characterEncoding=utf8 will be automatically recognized as utf8mb4, or this parameter can be omitted, and it will be automatically detected.
And autoReconnect=true must be added.

4. Some parameter configuration query commands

#Query the maximum number of mysql connections set
show global variables like 'max_conn%';
SELECT @@MAX_CONNECTIONS AS 'Max Connections';
view the maximum number of connections
show global status like 'Max_used_connections';
check whether the slow query log is enabled and the log location
show variables like 'slow_query%';
view slow query log timeout record time
show variables like 'long_query_time';
view link creation and current link number
show status like 'Threads%';
view database current link
show processlist;
view database configuration
show variables like '% quer%';

Five, completely uninstall mysql

1. Uninstall the software

After the yum remove mysql-community-server
is completed, use the rpm -qa|grep mysql command to check. If there are query results, use the yum remove name to clean them up. As shown in the figure:
insert image description here
Then use the command rpm -qa | grep -i mysql to view, if there is a result, use rpm -e name to uninstall. For example:
insert image description here

2. Delete files

rm -rf /var/lib/mysql
rm /etc/my.cnf
rm -rf /usr/share/mysql-8.0
If you need to reinstall, you can first grant permissions to the mysql directory before the installation is complete and started to prevent exceptions:
chmod - R 777 /var/lib/mysql

linux - mysql: check whether mysql is installed successfully

Order

rpm -q mysql
insert image description here

unmount database

Enter mysql, after entering the original password, you can directly use the following command to modify it, for example, change the password to root@123;
modify the password:

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root@123';

Guess you like

Origin blog.csdn.net/weixin_43401243/article/details/119696528