Install Mysql-Server and Mysql-Clinet under Linux

1. Check if mysql is installed

rpm -qa | grep -i mysql

2. If installed, delete the relevant RPM software package

rpm -e RPM软件包名(该名字是上一个命令查出来的名字)

3. Install the service side

 rpm -ivh MySQL-server-5.6.27-1.el6.x86_64.rpm
image-20210606160937757


If the above reasons occur, it means that the system has already installed other versions of mysql-libs package and mysql database files, causing incompatibility.
You can execute the following command to delete:

yum remove mysql-libs

4. Re-execute the Service installation command

 rpm -ivh MySQL-server-5.6.27-1.el6.x86_64.rpm

The screen of

image-20210606161442870


successful installation : the screen of successful installation but the problem still needs to be solved: the

image-20210606161600921


general problem is that when mysql was installed before, the relevant user group and user name were set, resulting in the default user of mysql cannot be created (but in this case, the installation is also successful , Solve this problem later)

5. Install Mysql-Client

 rpm -ivh MySQL-client-5.6.27-1.el6.x86_64.rpm
image-20210606161853620


The client installation is relatively easy, and there will be no major bugs

6. Check for installation

--查看密码(这里的用户名一般为mysql)
cat /etc/passwd|grep mysql
--查看用户组
cat /etc/group|grep mysql
image-20210606162013139
It can be seen that my user name is not mysql, because the installation time reported a problem that the user name could not be created. Here I changed the user name to root (this is the user name left during the installation of the previous version), and it can be displayed normally . (Follow-up, we will add the username of mysql)

7. Start mysql

service mysql start

Error screen.

image-20210606162427275


At this point, we see the problem and we don’t know what the pid file is. Even if cat goes to view the file, it means that there is no such file. At this time, we can only find the mysql installation directory and view the related log information.

  • Through var/lib/mysql/ above, we can guess the installation directory of mysql
cd /var/lib/mysql
image-20210606163008274


At this point, we can see the .err file with the same name as the above file, this is our error file. Click to view related information.

image-20210606163307947


From the above, we can know that the failure to start is because the mysql user does not exist. At this time, the solution we think of is to add the user name.

--添加用户
useradd mysql
image-20210606163655754


As can be seen from the above, we already have a default group, at this time you must use useradd -g to add users

useradd -g mysql mysql
image-20210606164033195


It will report to you that the permissions are insufficient, at this time we need to modify the relevant permissions

--查看权限
lsattr /etc/passwd
--去除权限限制
chattr -a /etc/passwd
--再去执行用户添加操作
useradd -g mysql mysql
image-20210606164242091


At this time there is another insufficient authority, we can modify the authority of /etc/shadow

lsattr /etc/shadow
chattr -a /etc/shadow
image-20210606164337873


In this way, the user name was finally added successfully. When we were happy with the service mysql start, we found that it failed to start again. It was

image-20210606164555601


really a fierce operation. Look at the record of 250. At this time, we have to look through the related err file again.

image-20210606164808700


From the related vocabulary above, it is not difficult to find that the related database table is missing.

After searching the information online, I found that the reason why'mysql.plugin' does not exist is because after the newly installed mysql service, it is generally necessary to perform database initialization operations to generate permissions-related tables. The execution commands are as follows:

/usr/bin/mysql_install_db --user=mysql

If the following error is reported, we can install the autoconf library

image-20210606165022962
yum -y install autoconf

After installation, go to perform related installation operations

/usr/bin/mysql_install_db --user=mysql

After the installation is successful, execute the mysql start command again

service mysql start

It can be regarded as clear after rain, our mysql finally started normally

image-20210606162520789