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
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
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.
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++*
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";
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
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=
This will enable the combination of ports and protocols. The port can be a separate port
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)
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
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