在linux中安装mysql6_Linux6上安装MySQL

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

20190105000249321492.png

然后选择:

20190105000249462122.png

20190105000249644746.png

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

[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安装成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值