Centos Tutorial for Installing MYSQL8.X
- 2021-07-06 12:04:02
- OfStack
Installation of MySQL (4, 5, 6 can be omitted)
Statement: CentOS version 7.6, installed MySQL version 8.0. 17
1. First, uninstall the mysql correlation, including MariaDB.
rpm -pa | grep mysql # Use the search results `rm -rf Filename ` Delete it, skip it if you don't have it
rpm -pa | grep mariadb # Use the search results `rm -rf Filename ` Delete it, skip it if you don't have it
find / -name mysql # Find and delete related folders, skip if not (ibid.)
find / -name mariadb # Find and delete related folders, skip if not (ibid.)
2. Back up the default repo source of centOS, and download the repo source of Alibaba Cloud or Netease to replace the default source.
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
3. Clean up the yum and create the yum cache.
sudo yum clean all
sudo yum makecache
4. View the content of mysql in the software source repository
yum repolist | grep mysql
5. Check whether the corresponding version of mysql is enabled
cat /etc/yum.repos.d/mysql-community
6. Set the version that needs to be installed to enable (I installed mysql Community Version 8.0 here)
yum-config-manager --enable mysql80-comminity
7. Perform the installation
yum install mysql-community-server.x86_64
8. Check the running status of mysql, which is not started by default after installation
# View MySQL Service running status, active Indicates that it has been started, inactive Indicates that it is not started, failed Indicates startup failure
systemctl status mysqld.service
# Start MySQL Services
systemctl start mysqld.service
# Stop MySQL Services
systemctl stop mysqld.service
# Restart MySQL Services
systemctl restart mysqld.service
9. View the initial password
The new version of mysql just installed automatically generates a temporary password, which is saved in ` /etc/log/mysqld. log '
cat /var/log/mysqld.log | grep "password"
10. Log in with your initial password
Copy the password of step 1, enter ` mysql-uroot-p password ', or press Enter without entering the password first, and paste the password at the prompt place (the password is not displayed, just paste it once).
11. Change the initial password
show databases;
use mysql;
# If you change your password to NewPassword! Include upper and lower case alphanumeric symbols as much as possible for safety
alter 'user'@'localhost' identified by 'NewPassword!';
12. Modify access permissions so that they can connect remotely
update user set Host='%' where User='root' and Host='localhost';
13. Refresh permissions
flush privileges;
14. Create a new user
create user User name identified by ' Password ';
# For example, creating a user specifies the hosts that can be accessed, and specifies the database tables that can be accessed and the corresponding permissions
create user User name @' Hostname ' identified by ' Password ';
grant select, update, create, delete on Database name . Table name to User name ;
15. Give permissions, remember to refresh permissions before they take effect
grant select on database name. Table name to user; # All permissions can use all
flush privileges;
MySQL Backup
Backup: Datasheet 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 exited with error code. See" systemctl status mysqld. service "journalctl-xe" for details. "= =
Solution:
Database initialization:
rm -rf /var/log/mysql.log
rm -rf /var/ib/mysql
Summarize