linux MySQL installation strategy

Keywords: MySQL MariaDB Linux Database

1.https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz 
Download the installation package.
The previous MySQL installation failed because of the selected version. It is recommended to select [Linux generic]
Decompression:
tar zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz 
//Put the file in the / usr/local/mysql path
mv mysql-5.7.21-linux-glibc2.12-x86_64/* /usr/local/mysql
Create MySQL users and groups
groupadd mysql
useradd -r -g mysql mysql
 Authorize all files under / usr/loacal/mysql to mysql users
chown -R mysql:mysql ./
Modify directory permissions
chown -R root:root .
chown -R mysql:mysql data
Modify database default directory
/etc/my.cnf
 Change the following two paths to
datadir=/usr/local/mysql
socket=/usr/local/mysql/mysql.sock
Initialize database
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
Add to service
cp support-files/mysql.server /etc/init.d/mysqld
start-up
service mysqld start

Boot up
chkconfig mysqld on
#Some settings for initializing mysql
mysql_secure_installation
//Enter
Enter current password for root (enter for none):
#y. Set the root password of mysql
Set root password?[Y/n] y
#The following are yes
Remove anonymous users?[Y/n] y
Disallow root login remotely?[Y/n] y
Remove test database and access to it?[Y/n] y
Reload privilege tables now?[Y/n] y
ThanksforusingMySQL!
Allow remote login
1.  mysql> use mysql; 
2.  mysql> select host,user,password from user; 
3.  mysql> update user set password=password('123456') where user='root'; 
4.  mysql> update user set host='%' where user='root' and host='localhost'; 
5.  mysql> flush privileges; 

Problems encountered during installation and solutions:

Error:
Starting MySQL.2018-02-06T04:41:24.042281Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log'
terms of settlement:
Manually create the mariadb.log file under / var/log/mariadb /
Error:
Starting MySQL... ERROR! The server quit without updating PID file (/var/lib/mysql/lichenyi.pid).
Solution:
/Manually create lichenyi.pid file under var/lib/mysql /
Error: mysqld: Table 'mysql.plugin' doesn't exist
 Solution:
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
 In the process of execution, if
2018-02-06 13:01:10 [ERROR]  The data directory needs to be specified
 Delete the data directory of mysql and execute again
Error:
Starting MySQL.The server quit without updating PID file 
Solution:
Delete my.cnf file under / etc / and start MySQL service again
Error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)
Solution:
Through the service mysqld status, it can be seen that the original mysqld PID file path has been changed before. Restore is OK
Error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'user mysql' at line 1
//Solution:
set password = password('mysql1234');
[root@lichenyi download]# yum update
Loaded plugins: fastestmirror
mysql-connectors-community                                                                                 | 2.5 kB 00:00:00   
mysql-tools-community                                                                                   | 2.5 kB 00:00:00   
mysql57-community                                                                                     | 2.5 kB 00:00:00   
(1/3): mysql-tools-community/x86_64/primary_db                                                                       | 39 kB 00:00:00   
(2/3): mysql-connectors-community/x86_64/primary_db                                                                    | 18 kB 00:00:00   
(3/3): mysql57-community/x86_64/primary_db                                                                         | 139 kB 00:00:00   
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:net-snmp-5.7.2-28.el7_4.1.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
---> Package mysql-community-libs.x86_64 0:5.7.21-1.el6 will be obsoleting
--> Processing Dependency: mysql-community-common(x86-64) >= 5.7.9 for package: mysql-community-libs-5.7.21-1.el6.x86_64
---> Package mysql-community-libs-compat.x86_64 0:5.7.21-1.el6 will be obsoleting
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:net-snmp-5.7.2-28.el7_4.1.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.21-1.el6 will be installed
--> Finished Dependency Resolution
Error: Package: 2:postfix-2.10.1-6.el7.x86_64 (@anaconda)
      Requires: libmysqlclient.so.18()(64bit)
      Removing: 1:mariadb-libs-5.5.56-2.el7.x86_64 (@base)
        libmysqlclient.so.18()(64bit)
      Obsoleted By: mysql-community-libs-5.7.21-1.el6.x86_64 (mysql57-community)
       ~libmysqlclient.so.20()(64bit)
Error: Package: 2:postfix-2.10.1-6.el7.x86_64 (@anaconda)
      Requires: libmysqlclient.so.18(libmysqlclient_18)(64bit)
      Removing: 1:mariadb-libs-5.5.56-2.el7.x86_64 (@base)
        libmysqlclient.so.18(libmysqlclient_18)(64bit)
      Obsoleted By: mysql-community-libs-5.7.21-1.el6.x86_64 (mysql57-community)
        Not found
Error: Package: 1:net-snmp-5.7.2-28.el7_4.1.x86_64 (@updates)
      Requires: libmysqlclient.so.18()(64bit)
      Removing: 1:mariadb-libs-5.5.56-2.el7.x86_64 (@base)
        libmysqlclient.so.18()(64bit)
      Obsoleted By: mysql-community-libs-5.7.21-1.el6.x86_64 (mysql57-community)
       ~libmysqlclient.so.20()(64bit)
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest


//terms of settlement:
yum remove mysql-libs   After removal, reinstall

Summary: to install MySQL, you must learn to view the error information through service mysqld status

Commands to use after installation

mysql -u root -p
select database();
show databases;
//Change Password
use user;
update user set host = '%' where user = 'root';
//Refresh service
FLUSH PRIVILEGES;

Posted by nariman on Mon, 13 Apr 2020 10:35:50 -0700