Linux6上安装MySQL

Posted 道法自然

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux6上安装MySQL相关的知识,希望对你有一定的参考价值。

mysql安装包下载:https://www.mysql.com/downloads/

然后选择:

把下载好的安装包传到服务器上的指定目录,然后解压:

[root@master mysql]# tar -xvf mysql-5.7.24-1.el6.x86_64.rpm-bundle.tar
mysql-community-test-5.7.24-1.el6.x86_64.rpm
mysql-community-client-5.7.24-1.el6.x86_64.rpm
mysql-community-libs-compat-5.7.24-1.el6.x86_64.rpm
mysql-community-libs-5.7.24-1.el6.x86_64.rpm
mysql-community-server-5.7.24-1.el6.x86_64.rpm
mysql-community-devel-5.7.24-1.el6.x86_64.rpm
mysql-community-embedded-5.7.24-1.el6.x86_64.rpm
mysql-community-embedded-devel-5.7.24-1.el6.x86_64.rpm
mysql-community-common-5.7.24-1.el6.x86_64.rpm

查询有没有安装MySQL:

 rpm -qa | grep mysql

如果安装,则卸载:
 rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64

安装下面的顺序进行安装:

 rpm -ivh mysql-community-common-5.7.24-1.el6.x86_64.rpm
 rpm -ivh mysql-community-libs-5.7.24-1.el6.x86_64.rpm
 rpm -ivh mysql-community-libs-compat-5.7.24-1.el6.x86_64.rpm
 rpm -ivh mysql-community-client-5.7.24-1.el6.x86_64.rpm
 rpm -ivh mysql-community-server-5.7.24-1.el6.x86_64.rpm

然后启动:

 service mysqld start

查看报错日志:

 grep \'temporary password\' /var/log/mysqld.log

2019-01-04T18:41:22.901300Z 1 [Note] A temporary password is generated for root@localhost: wsOk8mlgky*.

mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can\'t connect to local MySQL server through socket \'/var/lib/mysql/mysql.sock\' (2)

ps -A | grep -i mysql

查看状态:

/etc/rc.d/init.d/mysqld status

mysqld is stopped

重启:

 service mysqld start

Starting mysqld:                                           [  OK  ]

再次查看:

/etc/rc.d/init.d/mysqld status

mysqld (pid  2748) is running...

进入MySQL:

mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user \'root\'@\'localhost\' (using password: YES)

报错:

修改:vim /etc/my.cnf

添加:
[mysqld]
skip-grant-tables

重新启动:/etc/init.d/mysqld restart

Stopping mysqld:                                           [  OK  ]
/usr/bin/mysqld_safe: line 517: cd: /root/mysql/mysql5.7: Not a directory
Starting mysqld:                                           [  OK  ]

[root@master mysql5.7]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \\g.
Your MySQL connection id is 4
Server version: 5.7.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type \'help;\' or \'\\h\' for help. Type \'\\c\' to clear the current input statement.

mysql>

mysql> update user set authentication_string=password("mysql") where User=\'root\';    --更新一下密码

Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql>  flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

重新启动:

[root@master mysql5.7]# /etc/init.d/mysqld restart
Stopping mysqld:                                           [  OK  ]
/usr/bin/mysqld_safe: line 517: cd: /root/mysql/mysql5.7: Not a directory
Starting mysqld:                                           [  OK  ]
[root@master mysql5.7]# mysql -u root -p
Enter password:

Type \'help;\' or \'\\h\' for help. Type \'\\c\' to clear the current input statement.

mysql>

可以看到中间有个报错:
/usr/bin/mysqld_safe: line 517: cd: /root/mysql/mysql5.7: Not a directory

解决办法:
chmod -R 755 /root

[root@master /]# /etc/init.d/mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

完美解决。

mysql> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user \'root\'@\'localhost\' identified by \'mysql\';
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql>

至此,MySQL安装成功。

 

以上是关于Linux6上安装MySQL的主要内容,如果未能解决你的问题,请参考以下文章

阿里云linux6.9 64位安装mysql5.7.23记录

mysql for linux6.8单机版安装

搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程----转载

MySQL入门:Linux 6 RPM方式安装MySQL 8.0

如何在VMware软件上安装Red hat(红帽)Linux6.9操作系统

linux6 安装 ntopng