MySQL installation (4, 5, 6 can be omitted)
Disclaimer: CentOS version is 7.6, installed MySQL version is 8.0.17
rpm -pa | grep mysql #Use the search results`rm -rf file name`Delete, skip if not
rpm -pa | grep mariadb #Use the search results`rm -rf file name`Delete, skip if not
find /-name mysql #Find and delete related folders, skip if not (same as above)
find /-name mariadb #Find and delete related folders, skip if not (same as above)
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
cd /etc/yum.repos.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sudo yum clean all
sudo yum makecache
yum repolist | grep mysql
cat /etc/yum.repos.d/mysql-community
yum-config-manager --enable mysql80-comminity
yum install mysql-community-server.x86_64
# Check the running status of the MySQL service. Active means started, inactive means not started, and failed means failed to start
systemctl status mysqld.service
# Start the MySQL service
systemctl start mysqld.service
# Stop MySQL service
systemctl stop mysqld.service
# Restart the MySQL service
systemctl restart mysqld.service
The new version of mysql just installed will automatically generate a temporary password and save it in /etc/log/mysqld.log
cat /var/log/mysqld.log | grep "password"
Copy the password from the previous step and enter mysql -uroot -p password
, or press Enter without entering the password, and paste the password at the prompt (the password is not displayed, just paste it once).
show databases;
use mysql;
# For example, change the password to NewPassword!, For safety, try to include uppercase and lowercase alphanumerics plus symbols
alter 'user'@'localhost' identified by 'NewPassword!';
update user set Host='%' where User='root' and Host='localhost';
flush privileges;
create user username identified by'password';
# For example, to create a user and specify the host that can be accessed, and specify the database table and the corresponding permissions that it can access
create user username@'CPU name' identified by 'password';
grant select, update, create,delete on database name.Table name to user name;
grant select on database name. table name to user; # all permissions can use all
flush privileges;
MySQL backup
Backup: data table structure + data
mysqdump -u root db1 > db1.sql -p;
Backup: data table structure
mysqdump -u root -d db1 > db1.sql -p;
Import existing data into a database
Create a new database first
create database db10;
Import existing database files into db10 database
mysqdump -u root -d db10 < db1.sql -p;
== Note ==
== If the database reports an error: ==
== “Job for mysqld.service failed because the control process exited with error code. See “systemctl status mysqld.service” and “journalctl -xe” for details.”==
Solution:
Database initialization:
rm -rf /var/log/mysql.log
rm -rf /var/ib/mysql
to sum up
The above is the tutorial for installing MYSQL8.X in Centos introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message. The editor will reply to you in time. Thank you very much for your support to the ZaLou.Cn website!
If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!
Recommended Posts