1 Basic installation process of the software
1 uninstall existing mysql
1. Check whether the mysql software is installed on the system
# rpm -qa|grep -i mysql
2. Uninstall the installed software. Note: This uninstallation is not complete, but it is enough here.
# yum remove 'software name'
2 Prepare the source of mysqlrepo
Summary code:
# wget http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm # rpm -ivh mysql57-community-release-el7-7.noarch.rpm
CentOS 7
The yum
source of the default is not mysql
. So, to solve this problem we first download mysql
the installed repo
source.
# wget http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
# rpm -ivh mysql57-community-release-el7-7.noarch.rpm
After installation, you will get /etc/yum.repos.d/mysql-community.repo
and /etc/yum.repos.d/mysql-community-source.repo
two sources, you can go to the corresponding path to check.
3 install mysql
Use code summary:
# yum install mysql-server # yum install mysql-devel # yum install mysql
# rpm -qa | grep -i mysql
1. Install mysql-server
# yum install mysql-server
2 Install mysql-devel
# yum install mysql-devel
3. Install mysql
# yum install mysql
After the installation is complete, recheck the installed mysql
software.
# rpm -qa|grep -i mysql
Generally speaking, just install mysql-server and mysql-client.
2 Service switch operation
# service mysqld status View the current status of mysql # service mysqld stop stop mysql # service mysqld restart restart mysql # service mysqld start start mysql
3 Add MySQL to boot
# systemctl enable mysqld
4 Start the mysql service process
# systemctl start mysqld
Or use the following code: both start the mysql service, and the effect is the same.
# service mysqld start start mysql
5 Unable to log in problem solving
root
A password is required to log in to an account, but we don't have one.
The following is the detailed solution of this problem
1 Modify the configuration file to skip user authentication
1. /etc/my.cnf
Add in the fileskip-grant-tables。这里注意一下:我的skip-grant-tables放到了文件最后。
skip-grant-tables: The function is to skip the user authentication of mysql
Then directly enter mysql, you can log in to the database without any login parameters and press Enter directly;
2. reboot mysql
,service mysqld restart
After restarting, we can directly enter mysql to enter the mysql database, because we have skipped the user authentication of the mysql database.
3. Use mysql database
Use the command: user mysql;
4.show tables to view all tables
You will find a user table, which stores account information such as username, password, permissions, etc.
mysql> show tables; +---------------------------+ | Tables_in_mysql | +---------------------------+ | columns_priv | | db | | engine_cost | | event | | func | | general_log | | gtid_executed | | help_category | | help_keyword | | help_relation | | help_topic | | innodb_index_stats | | innodb_table_stats | | ndb_binlog_index | | plugin | | proc | | procs_priv | | proxies_priv | | server_cost | | servers | | slave_master_info | | slave_relay_log_info | | slave_worker_info | | slow_log | | tables_priv | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | | user | +---------------------------+ 31 rows in set (0.00 sec)
5. View account information
Execute the following command to view the user's account information.
select user,authentication_string from user;
From here we can see that the password in the mysql database is encrypted and irreversible. Once forgotten, it can't be found.
6. Modify the password of the root user
We can execute the following command to change the password of the root user:
update mysql.user set authentication_string=password('your password') where user='root';
7. After changing the password, delete all permissions
flush privileges;
8. Exit the database
exit
9. Recovery/etc/my.cnf文件
To restore /etc/my.cnf
, skip-grant-tables
delete or comment out.
10. reboot mysql
,service mysqld restart
service mysqld restart
So far, we have solved the problem of not knowing the password when logging in after mysql is installed. Everything is working fine now.
11. Verify that the login problem is successfully resolved
# rpm -qa|grep -i mysql
It can be seen that it has been solved perfectly. It's not easy going all the way down.
Code finishing in solving the login problem:
# vim / etc / my.cnf // Modify the configuration skip - grant - tables added to the end of my.cnf file # service mysqld restart // Restart the mysql service after modifying the configuration # mysql // After skipping user authentication, you can log in directly mysql > use mysql; // Switch database mysql > show tables; // View all tables mysql > select user ,authentication_string from user ; // View permission information mysql> update mysql.user set authentication_string=password('your password') where user='root'; //修改密码 mysql > flush privileges ; // Refresh to make changes take effect mysql > exit // Exit mysql [ root@iz2ze6adlpez0gy7j13vrmz ~ ] # vim / etc / my.cnf // Restore my.cnf file configuration, remove the last skip - grant - tables [ root@iz2ze6adlpez0gy7j13vrmz ~ ] # cat / etc / my.cnf // Check whether the restoration is successful [ root@iz2ze6adlpez0gy7j13vrmz ~ ] # service mysqld restart // Restart mysql service [ root@iz2ze6adlpez0gy7j13vrmz ~ ] # mysql - uroot - proot // Log in with the modified password
6. Solve the problem that the remote client cannot connect to the MySQL database
Now we want to access the mysql database on our Alibaba Cloud server locally and remotely. I am using the navicat software, but I find that I can't connect all the time.
The reason for this problem is because: my instance is a private network type. To be able to access it remotely, you need to open MySQL port 3306 to the outside world.
The following shows how to open port 3306 to the outside world.
After the configuration is complete, I try to connect to the MySQL database remotely again.