One, yum installation
New version (pro-tested and used many times, no problem)
Download the yum repository file of mysql
[root@localhost /]#wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
install mysql source
[root@localhost /]yum -y install mysql mysql57-community-release-el7-11.noarch.rpm
Install Mysql
yum -y install mysql-community-server
There is an error in the last line: the public key of mysql-community-libs-compat-5.7.41-1.el7.x86_64.rpm has not been installed,
so you need to import the public key (if it is mysql-community-release-el7-5.noarch.rpm version, this step is not required)
[root@localhost /]rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
install again
[root@localhost /]yum -y install mysql-community-server
2. Open the mysql service
start mysql
[root@localhost /]systemctl start mysqld.service
Set mysql to start automatically
[root@localhost /]systemctl enable mysqld.service
mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 四 2019-12-12 17:00:00 CST; 20s ago
View MySQL running status:
[root@localhost /]status mysqld.service
As long as active(running) appears , it means it is running
or this one too
[root@localhost /]ps aux|grep mysql
3. Configuration
Pay attention to open the host computer mysql service!
port release
In order to ensure that the external network can access mysql and use navicat to connect to the cloud server, a firewall needs to be set up to ensure that the firewall allows the port number of mysql to
open the firewall:
[root@localhost /]systemctl start firewalld
Add firewall release port number: mysql port, default 3306
[root@localhost /]firewall-cmd --zone=public --add-port=3306/tcp --permanent
Check port opening status:
[root@localhost /]firewall-cmd --list-ports
If it is an Alibaba Cloud cloud server, you also need to add ingress and egress release rules in the console security group
View and modify configuration
View mysql location:
[root@localhost /]which mysqld
Use the directory found by the above command to view the default path of the configuration file used by mysql
[root@localhost /]/usr/sbin/mysqld --verbose --help |grep -A 1 'Default options'
Edit some configuration files /etc/my.cnf
1. Custom port: add port=端口号
2. Remotely connect to the database and report an error:
"" must be added in the configuration file
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
3、character-set-server=utf8mb4
。。。
4. Password setting
①Find out the password in the log file by command:
Find the initial password
[root@localhost /]# grep "password" /var/log/mysqld.log
The password here is 7IB<p#rpwC(u
Log in
[root@localhost /]# mysql -uroot -p
Enter the above password and press Enter to confirm
Enter mysql and start changing the password
** Note that a semicolon must be added after each command**
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY '1AB<p#rpwC(y';
or
set password for root@localhost = password('1AB<p#rpwC(y')
Here set the password of the user named root, and the password is 1AB<p#rpwC(y
needs to set a complex password, if you don’t want to set a complex password, you can change the security level
Refresh the configuration to ensure immediate effect
mysql>flush privileges;
②Secret-free setting password (to be tested in this version):
1. Edit the my.cnf file
[root@localhost ~]# vim /etc/my.cnf
in [mysqld]
…
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
Add skip-grant-tables under
:wq save and exit
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
...
Restart the mysql service to make the configuration take effect
[root@localhost ~]# systemctl restart mysqld
2. Log in to mysql without a password (enter the user name and press Enter)
[root@localhost ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.46 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
3. Set the password by changing the password
mysql> update mysql.user set password=password('the password you want to set') where user='username';
mysql> update mysql.user set password=password('rootp') where user='root';
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4 Changed: 4 Warnings: 0
It will take effect directly without restarting the MySQL service.
The user information and permission settings in the current user and privilige tables will be extracted from the built-in library of the MySQL database into the memory.
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
quit
mysql> quit;
Bye
4. Modify my.cnf and restore the configuration
[root@localhost ~]# vim /etc/my.cnf
Delete the skip-grant-tables previously inserted in [mysqld]
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
...
Restart the mysql service and the configuration will take effect
[root@localhost /]# systemctl restart mysqld
5. Login verification
[root@localhost ~]# mysql -u root -p
Enter the password rootp just configured after pressing Enter