Centos7通过rpm包安装MySQL

1、首先下载mysql的rpm包

这个自己去官网下载即可

2、通过WinSCP上传到虚拟机

3、查看rpm包

[root@iZwz9673xvp1zsk6s1g24rZ mysql]# ll
total 585024
-rw-r--r-- 1 root root  25398288 Oct  5  2018 mysql-community-client-5.7.24-1.el7.x86_64.rpm
-rw-r--r-- 1 root root    280896 Oct  5  2018 mysql-community-common-5.7.24-1.el7.x86_64.rpm
-rw-r--r-- 1 root root   3840412 Oct  5  2018 mysql-community-devel-5.7.24-1.el7.x86_64.rpm
-rw-r--r-- 1 root root  46773880 Oct  5  2018 mysql-community-embedded-5.7.24-1.el7.x86_64.rpm
-rw-r--r-- 1 root root  24078240 Oct  5  2018 mysql-community-embedded-compat-5.7.24-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 130082964 Oct  5  2018 mysql-community-embedded-devel-5.7.24-1.el7.x86_64.rpm
-rw-r--r-- 1 root root   2272368 Oct  5  2018 mysql-community-libs-5.7.24-1.el7.x86_64.rpm
-rw-r--r-- 1 root root   2116016 Oct  5  2018 mysql-community-libs-compat-5.7.24-1.el7.x86_64.rpm
-rw-r--r-- 1 root root  56029544 Oct  5  2018 mysql-community-minimal-debuginfo-5.7.24-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 173096508 Oct  5  2018 mysql-community-server-5.7.24-1.el7.x86_64.rpm
-rw-r--r-- 1 root root  15167212 Oct  5  2018 mysql-community-server-minimal-5.7.24-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 119909528 Oct  5  2018 mysql-community-test-5.7.24-1.el7.x86_64.rpm

4、依次安装

rpm -ivh mysql-community-common-5.7.24-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.24-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.24-1.el7.x86_64.rpm
yum install -y libaio
rpm -ivh mysql-community-server-5.7.24-1.el7.x86_64.rpm

在安装rpm -ivh mysql-community-server-5.7.24-1.el7.x86_64.rpm的时候需要先安装libaio,否则报错如下:

root@iZwz9673xvp1zsk6s1g24rZ mysql]# rpm -ivh mysql-community-server-5.7.24-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	libaio.so.1()(64bit) is needed by mysql-community-server-5.7.24-1.el7.x86_64
	libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.24-1.el7.x86_64
	libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.24-1.el7.x86_64

5、初始化MySQL

mysqld --initialize

6、启动MySQL

service mysqld start

如果启动MySQL报错如下:

[root@iZwz9673xvp1zsk6s1g24rZ mysql]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.

则将删除/var/lib/mysql目录 rm -rf /var/lib/mysql

[root@iZwz9673xvp1zsk6s1g24rZ mysql]# rm -rf /var/lib/mysql
[root@iZwz9673xvp1zsk6s1g24rZ mysql]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@iZwz9673xvp1zsk6s1g24rZ mysql]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-08-07 14:08:16 CST; 10s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 26391 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 26317 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 26394 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─26394 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Aug 07 14:08:11 iZwz9673xvp1zsk6s1g24rZ systemd[1]: Starting MySQL Server...
Aug 07 14:08:16 iZwz9673xvp1zsk6s1g24rZ systemd[1]: Started MySQL Server.

7、查看MySQL默认随机生成的密码

grep 'temporary password' /var/log/mysqld.log
[root@iZwz9673xvp1zsk6s1g24rZ mysql]# grep 'temporary password' /var/log/mysqld.log
2019-08-07T06:06:44.482324Z 1 [Note] A temporary password is generated for root@localhost: 0a%hu(TtgpTf
2019-08-07T06:08:12.570098Z 1 [Note] A temporary password is generated for root@localhost: <;Upj1qhi*1f

8、登陆MySQL并修改密码

[root@iZwz9673xvp1zsk6s1g24rZ mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.24

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> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

如上所示修改密码报错,执行下面的命令

set global validate_password_policy=0;
set global validate_password_length=1;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

再次修改密码:

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update mysql.user set authentication_string=password('123456') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 2  Changed: 1  Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值