[Switch] CentOS7 64-bit installation mysql tutorial

Starting from the latest version of the linux system, the default is Mariadb instead of mysql! Here is still taking mysql as an example to show

1、 First check whether the system is equipped with mysql

rpm -qa | grep mysql

This returns a null value, indicating that it is not installed

Executing the installation command here is invalid, because centos-7 is Mariadb by default, so executing the following command just updates the Mariadb database

yum install mysql

Delete available

yum remove mysql

2、 Download the repo source of mysql##

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

Install the mysql-community-release-el7-5.noarch.rpm package

sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

After installing this package, you will get two mysql yum repo sources: /etc/yum.repos.d/mysql-community.repo, /etc/yum.repos.d/mysql-community-source.repo.

3、 Install mysql

sudo yum install mysql-server

You can install it according to the steps, but after the installation is complete, there is no password and you need to reset the password.

Check mysql again after installation

If an error is reported, the content contains

Error: Package: mysql-community-libs-5.6.35-2.el7.x86_64(mysql56-community)
   Requires: libc.so.6(GLIBC_2.17)(64bit)
Error: Package: mysql-community-server-5.6.35-2.el7.x86_64(mysql56-community)
   Requires: libc.so.6(GLIBC_2.17)(64bit)
Error: Package: mysql-community-server-5.6.35-2.el7.x86_64(mysql56-community)
   Requires: systemd
Error: Package: mysql-community-server-5.6.35-2.el7.x86_64(mysql56-community)
   Requires: libstdc++.so.6(GLIBCXX_3.4.15)(64bit)
Error: Package: mysql-community-client-5.6.35-2.el7.x86_64(mysql56-community)
   Requires: libc.so.6(GLIBC_2.17)(64bit)
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

solve:

# yum install glibc.i686
# yum list libstdc++*

4、 reset Password##

Before resetting your password, you must first log in

# mysql -u root

This error may be reported when logging in: ERROR 2002 (HY000): Can't connect to local MySQL server through socket'/var/lib/mysql/mysql.sock' (2), the reason is /var/lib/mysql Access rights issue. The following command changes the owner of /var/lib/mysql to the current user:

# sudo chown -R openscanner:openscanner /var/lib/mysql

If report chown: invalid user: "openscanner:openscanner" error, change the command and use ll to view the directory permission list

chown root /var/lib/mysql/
ll

Attach:

① Change file owner(chown )[root@linux ~]#chown account name file or directory
② Use the command chgrp to change the user group of the file
[ root@linux ~]#chgrp group name file or directory
③ After modifying the directory permissions, the default is to modify only the permissions of the current level. If the subdirectory is also recursive, you need to add the R parameter
Chown -R :Recursively,Together with all files and directories in subdirectories

Then, restart the service:

service mysqld restart

Next log in to reset your password:

mysql -u root -p
mysql > use mysql;
mysql > update user set password=password('123456') where user='root';
mysql > exit;

It will take effect after restarting the mysql service. # service mysqld restart

If necessary, add the following command line to add remote connection capabilities for root. The link password is "root" (excluding double quotes)

mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";

5、 Query the database encoding format, make sure it is UTF-8

show variables like "%char%";

Need to modify the encoding format to utf8mb4, when importing the database sql, please make sure that the sql file is utf8 encoding

Enter after entering the mysql command line

set names utf8mb4;

Check again and modify successfully

6、 Open 3306 port number

The firewalld firewall (centos-7) runs the command and restarts:

firewall-cmd --zone=public--add-port=3306/tcp --permanent
firewall-cmd --reload

When running, it may report an error FirewallD is not running because the firewall is not turned on.

systemctl status firewalld //Check the firewall status, dead is not turned on
systemctl start firewalld   //Turn on the firewall

iptables firewall (centos6.5 and before) run command

vim /etc/sysconfig/iptables

Commonly used commands:

In the upper left corner of the keyboard"ESC",Exit editing
Enter "colon", that is":"(No double quotes required), A colon will appear below, waiting for input
Enter WQ: save and exit, w means write, q means exit. Can be used alone

Add the following command line in the file and restart

- A INPUT -p tcp -m state --state NEW -m tcp --dport 3306-j ACCEPT
# service iptables restart

It may report an error Failed to restart iptables.service: Unit not found when running.

In CentOS 7 or RHEL 7 or Fedora, the firewall is managed by firewalld,

If you want to add a range of exception ports such as 1000-2000

The syntax command is as follows: enable zone port and protocol combination
firewall-cmd [--zone=] --add-port=[-]/ [--timeout=]
This will enable the combination of ports and protocols. The port can be a separate port Or a port range - . The protocol can be tcp or udp.
The actual command is as follows:

firewall-cmd --zone=public--add-port=80/tcp --permanent (--permanent takes effect permanently, and will become invalid after restart without this parameter)

firewall-cmd --zone=public--add-port=1000-2000/tcp --permanent 
Reload
firewall-cmd --reload
View
firewall-cmd --zone=public--query-port=80/tcp
delete
firewall-cmd --zone=public--remove-port=80/tcp --permanent

External link access effect (usually establish sql database and data table, it is recommended to control through remote link, intuitive and easy to operate)

7、* There is an error...interface can be insecure*

7.1、 Modify the database configuration file

1、 We need to modify the database configuration file, this depends on our database configuration, some are in /etc/my.cnf, some are in /etc/my.conf

We need to add a script in the [client] section:

socket=/var/lib/mysql/mysql.sock( mysql.sock file location)
host=localhost
user=Database user
password='Database password'

The parameters here must be modified to our own.

2、 Export and import databases using commands
In fact, at this time, if we use the method described in "Detailed use of the mysqldump command to backup and restore MySQL data usage http://www.laozuo.org/5047.html", the method introduced can also be used. Although there are still error messages, the database can still be exported. You must be a person who pursues details like Lao Zuo, and there is no problem at all, but we can use the following commands to export and import, and there is no error message.

Export database

mysqldump --defaults-extra-file=/etc/my.cnf database > database.sql

Import database

mysql --defaults-extra-file=/etc/my.cnf database < database.sql

Here we can see that the above command is different from the usual quick import and import commands. We need to load the MYSQL configuration file we configured. This "/etc/my.cnf" should be modified according to our actual path. There is no error prompt for exporting backup and importing with such commands.

Log in to the database

# mysql -u root -p

7.2、 Use mysql_config_editor

1、 Set encryption mode

mysql_config_editor set--login-path=local --host=localhost --user=db_user --password

"Db_user" needs to be changed to our own database user name. After pressing Enter, we will be prompted to enter the database password, and we will still enter it.

2、 Perform backup

mysqldump -u db_user -pInsecurePassword my_database | gzip > backup.tar.gz

Modify the user and user name and database password according to our data information, and perform the backup. The old left test still has an error message here, but the database can be backed up.

Modify the password of the root user of MySQL:

mysql -u root mysql 
mysql>use mysql; 
mysql>desc user; 
mysql> GRANT ALL PRIVILEGES ON . TO root@”%” IDENTIFIED BY “root”;//Add the ability to remotely connect to root.
mysql>update user set Password =password(‘xxxxxx’) where User=’root’; 
mysql>select Host,User,Password from user where User=’root’; 
mysql>flush privileges; 
mysql>exit;

Log in again: mysql -u root -p

deletefrom mysql.user where user=”;← Delete anonymous users
select user,host from mysql.user;← View user information

Recommended Posts

[Switch] CentOS7 64-bit installation mysql tutorial
Centos7 install Mysql8 tutorial
Mysql8.0.15 installation configuration (centos7)
Linux CentOS 7 installation tutorial
MySQL 8.0 installation, deployment and configuration tutorial on CentOS 8
Centos mysql installation and configuration
CentOS 6.x installation mysql5.7 record
Hyper-V + CentOS7 installation video tutorial
Centos7.4 environment installation lamp-php7.0 tutorial
Centos iso image file installation tutorial
Centos7 installation of Dameng database tutorial
CentOS6 minimal installation KVM detailed tutorial
Centos8 installation diagram (super detailed tutorial)
2019-07-09 CentOS7 installation
centos7_1708 installation
Centos7 mysql database installation and configuration
CentOS 7 system installation and configuration graphic tutorial
Installation and use of Mysql under CentOS
CentOS container installation in Docker uses MySQL
CentOS7 installation zabbix 4.0 tutorial (graphics and text)
Jenkins installation and deployment tutorial under CentOS 7
Detailed tutorial on installing MySQL 8 in CentOS 7
Novice learning Linux (eight) ---- MySql installation (Centos7)
Centos5 installation guide
CentOS7.2 install Mysql5.7.13
Python2.7 [Installation Tutorial]
Python - centos6 installation
CentOS install mysql
Docker installation (CentOS7 installation)
CentOS8 install MySQL8.0
CentOS7 docker installation
CentOS7 install MySQL8
Centos MySQL8 configuration
centos 7.5 install mysql5.7.17
The most complete centos installation tutorial in history
CentOS 6.5 system installation and configuration graphic tutorial (detailed graphic)
Linux (CentOS7) using RPM to install mysql 8.0.11 tutorial
Centos7 installation of PHP and Nginx tutorial detailed
MySQL 8.0 installation and deployment under CentOS, super detailed!
CentOS7.3 64 bit, build Zabbix3.4
CentOS online installation RabbitMQ3.7
01 CentOS 7.6 switch system language
Zabbix 2.2.20 installation details (Centos6.9)
CentOS6.5 offline install MySQL5.6.26
Install MySQL5.7 in centos7
Centos install MYSQL8.X tutorial
Centos install elasticsearch tutorial
Centos source installation Python3
Linux system-Centos7 installation tutorial
lamp (centos7) installation lamp environment
Centos8 (minimal installation) a new installation of Python3.8+pip method tutorial
CentOS 7.2 Yum install MySQL 5.6
Centos7 install kubernetes tutorial
Centos7 mqtt cluster installation
Graphical installation of CentOS8
Install mysql under Centos 7
CentOS7 reset MySQL8.0 password
Centos7 install Mysql database
Linux notes (1): CentOS-7 installation
Redis3 installation under Centos7
Install mysql5.1 under CentOS6.5