centos7 下mysql5.7安装与配置 (rpm安装包方式)

1、卸载系统自带的 mariadb-lib

[root@iZj6ceftauv7x5u8lzo95uZ temp]# rpm -qa|grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@iZj6ceftauv7x5u8lzo95uZ temp]#  rpm -e mariadb-libs-5.5.52-1.el7.x86_64 --nodeps

2、下载 mysql rpm安装包

[root@iZj6ceftauv7x5u8lzo95uZ temp]# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar

3、解压 mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar 

[root@iZj6ceftauv7x5u8lzo95uZ temp]#  tar -xvf mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar 

3、安装过程

[root@iZj6ceftauv7x5u8lzo95uZ temp]#  rpm -ivh mysql-community-common-5.7.21-1.el7.x86_64.rpm 
[root@iZj6ceftauv7x5u8lzo95uZ temp]#  rpm -ivh mysql-community-libs-5.7.21-1.el7.x86_64.rpm
[root@iZj6ceftauv7x5u8lzo95uZ temp]#  rpm -ivh mysql-community-client-5.7.21-1.el7.x86_64.rpm
[root@iZj6ceftauv7x5u8lzo95uZ temp]#  rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm 


注:执行  rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm 

出现错误:warning: mysql-community-server-5.7.21-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.21-1.el7.x86_64
    libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.21-1.el7.x86_64
    libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.21-1.el7.x86_64
错误原因:缺少依赖包libaio

解决方式: yum install libaio

4、数据库初始化

为了保证数据库目录为与文件的所有者为 mysql 登陆用户,如果你是以 root 身份运行 mysql 服务,需要执行下面的命令初始化 mysqld --initialize --user=mysql

如果是以 mysql 身份运行,则可以去掉 --user 选项。

另外 --initialize 选项默认以“安全”模式来初始化,则会为 root 用户生成一个密码并将该密码标记为过期,登陆后你需要设置一个新的密码,而使用 --initialize-insecure 命令则不使用安全模式,则不会为 root 用户生成一个密码。

这里演示使用的 --initialize 初始化的,会生成一个 root 账户密码,密码在log文件里,最下面一行FadKojZte5#T就是自动生成的密码

[root@iZj6ceftauv7x5u8lzo95uZ temp]# mysqld --initialize --user=mysql
[root@iZj6ceftauv7x5u8lzo95uZ temp]# cat /var/log/mysqld.log 
2018-02-24T01:43:06.058882Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-02-24T01:43:08.197289Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-02-24T01:43:08.522379Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-02-24T01:43:08.600024Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 10ba2bbd-1904-11e8-b9e6-00163e006097.
2018-02-24T01:43:08.604194Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-02-24T01:43:08.608270Z 1 [Note] A temporary password is generated for root@localhost: FadKojZte5#T

5、启动mysql数据库

[root@iZj6ceftauv7x5u8lzo95uZ temp]# systemctl start mysqld.service

6、访问数据库,密码为上面的随机自动生成的密码

[root@iZj6ceftauv7x5u8lzo95uZ temp]# mysql -uroot -p

7、修改随机密码

该密码被标记为过期了,如果想正常使用还需要修改密码

 ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

8、开启mysql的远程访问

添加一个用户供其远程连接访问

# GRANT ALL PRIVILEGES ON *.* TO 'liuyingjun'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
# flush privileges;
# systemctl restart  mysqld
 

 

转载于:https://my.oschina.net/foxneil/blog/1623350

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值