Install Mysql service on Linux

Environmental preparation

  • CentOS-7-x86_64-Minimal-1708
  • Mysql 5.6.40

Install and deploy

1. Download the repo source of mysql

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

2. 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-server

$ sudo yum install mysql-server

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

4. Reset mysql password

$ 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 issues. The following command changes the owner of /var/lib/mysql to the current user:

$ sudo chown -R root:root /var/lib/mysql

restart mysql service

$ service mysqld restart

Next, log in to reset your password:

$ mysql -u root //Enter mysql console directly

View version: select version();

mysql > use mysql;
mysql > update user set password=password(‘12345’) where user=’root’;

mysql > exit;

SELECT User, Password, Host FROM user;
re-login: mysql -u root -p 12345

flush privileges;

The mysql remote cannot connect to the problem.

First, the system releases the port, and then the user table Update host is %
+——+——————————————————————–+——+
| User | Password | Host |
+——+———————————————————————–+——+
| root | *00A51F3F48415C7D4E8908980D443C29C69B60C9 | % |
+——+———— —————————————————————–+——+

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326101680&siteId=291194637