Install mysql on linux using glibc version installation

1. Check before installation

1.1 Check the linux system version

[root@localhost ~]# cat /etc/system-release

Note: Xiaosheng’s version is linux 64 bit: CentOS Linux release 7.4.1708 (Core)

1.2 Check whether mysql is installed

[root@localhost ~]# rpm -qa | grep mysql

If there is a mysql installation file, the version information of the mysql installation will be displayed

如:mysql-connector-odbc-5.2.5-6.el7.x86_64

Uninstall the installed MySQL, uninstall the mysql command, as follows:

[root@localhost ~]# rpm -e --nodeps mysql-connector-odbc-5.2.5-6.el7.x86_64

Note for details:
  Check whether the mariadb database exists in the system. If there is, it must be uninstalled, otherwise it may conflict with mysql.
  The system installation mode is minimal installation, so there is no such database.
  Check if mariadb is installed: [root@localhost ~]# rpm -qa | grep mariadb
  If yes, uninstall it:
systemctl stop mariadb
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-5.5.52-1.el7 .x86_64
rpm -e --nodeps mariadb-server-5.5.52-1.el7.x86_64
rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
  1.3 System memory check

Check the virtual memory size of the Linux system. If the memory is less than 1G, the following error message may be generated when starting mysql:

Starting mysqld (via systemctl): Job for mysqld.service failed because the control process exited with error code.

See “systemctl status mysqld.service” and “journalctl -xe” for details.[FAILED]

When Xiaosheng first installed it, he used the automatic partitioning of the virtual machine, and the memory was set to 1G. As a result, a lot of energy and time were spent on debugging and the startup was not successful.

After installing mysql through lnmp, mysql is not running is displayed. The error is as follows:
  Starting MySQL...The server quit without updating PID file (/usr/local/mysql/var/localhost.localdomain.pid)
Various solutions are found on the Internet, most of which are file permissions and mysql logs are too large and heavy Installation and other issues. I tried the solutions one by one, but they all
came up ... Finally, I opened the installation tutorial https://lnmp.org/install.html on the official website of lnmp, and realized that it was because the mysql version I chose during installation was 5.6. , And installing mysql version 5.6 and above requires the server's memory at least 1G. And I installed it on the VPS. The memory is 256MB, there is a problem if there is no error. Instantly heart-stuck.
Finally, uninstall lnmp first, and then install it. The installation can refer to the official tutorial.

2. Download and upload the mysql installation package from the mysql official website

2.1 Download the mysql installation package

Xiaosheng uses mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

2.2 Upload the installation file to the linux system

Use ftp to upload to the linux system, upload to the /var/ftp/pub file directory

Insert picture description here

Note
  for details: For security issues, it is recommended to use the md5sum command to check the file source: [root@localhost pub]# md5sum mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

1、下载tar包,这里使用wget从官网下载
 
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
 
2、将mysql安装到/usr/local/mysql下
 
# 解压
 
tar -xvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
 
# 移动
 
mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/
 
# 重命名
 
mv /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
 
3、新建data目录
 
mkdir /usr/local/mysql/data
 
4、新建mysql用户、mysql用户组
 
# mysql用户组
 
groupadd mysql
 
# mysql用户
 
useradd mysql -g mysql
 
5、将/usr/local/mysql的所有者及所属组改为mysql
 
chown -R mysql.mysql /usr/local/mysql
 
6、配置
 
/usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
 
# 如果出现以下错误:
 
复制代码
2018-07-14 06:40:32 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2018-07-14 06:40:32 [ERROR]   Child process: /usr/local/mysql/bin/mysqldterminated prematurely with errno= 32
2018-07-14 06:40:32 [ERROR]   Failed to execute /usr/local/mysql/bin/mysqld --bootstrap --datadir=/usr/local/mysql/data --lc-messages-dir=/usr/local/mysql/share --lc-messages=en_US --basedir=/usr/local/mysql
-- server log begin --
 
-- server log end --
复制代码
# 则使用以下命令:
 
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
# 如果出现以下错误:
 
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
# 则执行以下命令:
 
yum -y install numactl
 
# 完成后继续安装:
 
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
# 编辑/etc/my.cnf
 
复制代码
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
# 取消密码验证
skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
复制代码
7、开启服务
 
# 将mysql加入服务
 
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
 
# 开机自启
 
chkconfig mysql on
 
# 开启
 
service mysql start
 
8、设置密码
 
# 登录(由于/etc/my.cnf中设置了取消密码验证,所以此处密码任意)
 
/usr/local/mysql/bin/mysql -u root -p
 
# 操作mysql数据库
 
>>use mysql;
 
# 修改密码
 
>>update user set authentication_string=password('你的密码') where user='root';
 
>>flush privileges;
 
>>exit;
 
9、将/etc/my.cnf中的skip-grant-tables删除
 
10、登录再次设置密码(不知道为啥如果不再次设置密码就操作不了数据库了)
 
/usr/local/mysql/bin/mysql -u root -p
 
 >>ALTER USER 'root'@'localhost' IDENTIFIED BY '修改后的密码';
 
>>exit;
 
11、允许远程连接
 
/usr/local/mysql/bin/mysql -u root -p
 
>>use mysql;
 
>>update user set host='%' where user = 'root';
 
>>flush privileges;
 
>>eixt;
 
12、添加快捷方式
 
ln -s /usr/local/mysql/bin/mysql /usr/bin

Guess you like

Origin blog.csdn.net/qq_2662385590/article/details/112970564