当前位置: 移动技术网 > IT编程>数据库>Mysql > MySQL——安装

MySQL——安装

2019年03月16日  | 移动技术网IT编程  | 我要评论

1. 下载源: 

该源目前为8.0版本,如果需要最新请退至根目录找。

wget http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql80-community-release-el7-2.noarch.rpm    #下载源

2. 安装源

yum install mysql80-community-release-el7-2.noarch.rpm  

3. 查看是否安装完成

yum repolist enabled | grep "mysql.*-community.*"   

查看后会出现,表明为正常安装。

可以修改vi /etc/yum.repos.d/mysql-community.repo源,改变默认安装的mysql版本。

比如要安装8.0版本,将5.7源的enabled=1改成enabled=0。然后再将8.0源的enabled=0改成enabled=1即可。

 4. 安装mysql

yum install mysql-community-server

5. 启动mysql服务

systemctl start mysqld
systemctl restart mysqld    #重启mysql服务

6. 查看mysql的启动状态

systemctl status mysqld

7.设置开机启动

systemctl enable mysqld
systemctl daemon-reload

8. 查看mysql默认密码:

mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:

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

9. 进入mysql修改密码:

mysql -uroot -p
password
set password for 'root'@'localhost'=password('password'); 

注意:mysql8.0默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示error 1819 (hy000): your password does not satisfy the current policy requirements错误,如下图所示 

查看mysql密码策略:

mysql> show variables like '%password%';

mysql密码策略
validate_password_policy:密码策略,默认为medium策略
validate_password_dictionary_file:密码策略文件,策略为strong才需要
validate_password_length:密码最少长度
validate_password_mixed_case_count:大小写字符长度,至少1个
validate_password_number_count :数字至少1个
validate_password_special_char_count:特殊字符至少1个

更详细的mysql密码信息,请见:

10. 添加远程用户

默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,我添加一个新的帐户:

8.0以前的版本:

grant all privileges on *.* to 'mysql'@'%' identified by 'mysql123!@#' with grant option;

8.0以后的版本:

create user 'zabbix'@'localhost' identified by '123456';      #创建一个用户
grant all on zabbix.* to 'zabbix'@'localhost' with grant option;   #授予zabbix的远程登录权限。

查看mysql下所用户的访问权限:

select * from information_schema.user_privileges;

11. 更改mysql默认编码格式

show variables like '%character%';   #查看默认编码格式

修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

[mysqld]
character_set_server=utf8
init_connect='set names utf8'
default_authentication_plugin = mysql_native_password    #更改默认密码认证方式。

默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网