博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux配置Mysql 数据库
阅读量:200 次
发布时间:2019-02-28

本文共 4452 字,大约阅读时间需要 14 分钟。

不要吐槽我 我是自己保存看的 有点乱 有数据库配置问题 可以咨询我!

在这里插入图片描述

安装mysql5.7

1、先把postfix 和mariadb-libs卸载掉,不然的会有依赖包冲突:
[root@wolfcode]# rpm -e postfix mariadb-libs

2、安装mysql的依赖net-tools和 perl

yum -y install net-tools perl

3、安装mysql-common包:

[root@wolfcode]# rpm -ivh mysql-community-common-5.7.22-1.el7.x86_64.rpm

4、安装mysql-libs包:

[root@wolfcode]# rpm -ivh mysql-community-libs-5.7.22-1.el7.x86_64.rpm --nodeps --force

因为第四步报错:

error: Failed dependencies:
mariadb-libs is obsoleted by mysql-community-libs-5.7.22-1.el7.x86_64
所以下载报错依赖:
下载 yum -y remove mariadb-libs

5、安装mysql-client包;

[root@wolfcode]# rpm -ivh mysql-community-client-5.7.22-1.el7.x86_64.rpm --nodeps --force

6、安装mysql-server包

[root@wolfcode]# rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm --nodeps --force

报错:error: Failed dependencies:

libaio.so.1()(64bit) is needed by mysql-community-server-5.7.22-1.el7.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.22-1.el7.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.22-1.el7.x86_64
下载
yum install libaio

5、设置开机启动:

[root@wolfcode]# systemctl enable mysqld

6、启动MySql服务

[root@wolfcode]# systemctl start mysqld
systemctl start mysqld.service 启动
systemctl stop mysqld.service 停止
systemctl restart mysqld.service 重启

查看错误信息

journalctl -xe

启动报错: systemctl status mysqld.service 这个语句是查看数据库的安装状态

7、由于MySQL5.7安装好后会给root用户分配一个临时密码,所以我们先查看临时密码

[root@wolfcode]# grep ‘temporary password’ /var/log/mysqld.log
2018-06-01T19:40:08.341478Z 1 [Note] A temporary password is generated for root@localhost: Ct<pX.k7S(=w
冒号后面的就是root用户的临时密码:Ct<pX.k7S(=w

8、使用临时密码登录

[root@wolfcode]# mysql -u root -p
输入密码:Ct<pX.k7S(=w

9、设置root的密码

mysql>ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘WolfCode_2017’;
mysql> exit
注意:mysql5.7增加了安全级别,密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。

10、用新密码登陆

[root@wolfcode]# mysql -u root -p
输入密码:WolfCode_2017

11、开放远程登录权限

mysql> GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘qwer@123456’ WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;

12、开放mysql的3306端口

[root@wolfcode]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
[root@wolfcode]# firewall-cmd --reload

如果出现乱码:

在链接地址栏后添加useUnicode=true&characterEncoding=utf-8

GRANT ALL ON . TO root@’%’ IDENTIFIED BY ‘123456’ WITH GRANT OPTION;

1.SET PASSWORD = PASSWORD(‘qwer@123456’);

设置密码的时候 不要设置太简单了 !!5.7出错

下面图是重置密码的时候 使用的命令

Mysql>Set password=password(‘新密码’) 这个是登录数据库以后才能使用这样的命令去修改当前的密码( 5.7版本 由于升级了 保护性的原因 , 所以会有临时密码, 临时密码通过上面的日志文件查看, 但是有可能出现临时文件查看不了 临时密码 , 所以需要去 vi /etc/my.cnf 去这个配置文件下面, 如果没有这个文件 可以从现有的 服务器去找一个对应的 copy里面的内容 ,下面图二 红框里面 先把他放开,(这样你就不需要临时密码,省去密码验证,直接登录mysql 然后在修改重置密码, Use mysql
update user set authentication_string = password(“admin123456!!”) where user=“root” ;
) 先 use mysql 在去修改 ,因为5.7的版本 authentication_string 这个字段才是数据库默认的密码字段 修改成功以后 在去my.cnf 的配置文件 把图二那个红框给注解调#,然后在去 重新登录 )
登录数据库命令:mysql -u root -p
查看状态: journalctl -xe
1:vi /etc/my.cnf 修改完配置需要重新启动 一下
systemctl start mysqld.service 启动
systemctl stop mysqld.service 停止
systemctl restart mysqld.service 重启

在mysql 修改对应的东西 需要刷新 :flush privileges

图一

在这里插入图片描述

图二:

这个是my.cnf的配置
在这里插入图片描述

```handlebars5.7的数据库版本配置  我用的之前的 服务区成功的版本配置 反正我成功 连接了# For advice on how to change settings please see# # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html #[mysqld]#skip-grant-tables# ## # Remove leading # and set to the amount of RAM for the most important data# # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.# # innodb_buffer_pool_size = 128M# ## # Remove leading # to turn on a very important data integrity option: logging# # changes to the binary log between backups.# # log_bin# ## # Remove leading # to set options mainly useful for reporting servers.# # The server defaults are faster for transactions and fast SELECTs.# # Adjust sizes as needed, experiment to find the optimal values.# # join_buffer_size = 128M# # sort_buffer_size = 2M# # read_rnd_buffer_size = 2Mdatadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock## # Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0## # Recommended in standard MySQL setup# #sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES# #characterinit_connect='SET collation_connection = utf8_unicode_ci'init_connect='SET NAMES utf8mb4'character-set-server=utf8mb4collation-server=utf8mb4_unicode_ci# #skip-character-set-client-handshake[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid[mysql]default-character-set=utf8mb4

图三:这个是 用来操作 下面有说明

在这里插入图片描述

成功连接 Mysql

在这里插入图片描述

转载地址:http://mqls.baihongyu.com/

你可能感兴趣的文章