Linux 安装mysql
1、到mysql 的官网下载mysql 的yum包
下载并安装MySQL官方的 Yum Repository
wget -i -c https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
使用上面的命令就直接下载了安装用的Yum Repository,大概25KB的样子,然后就可以直接yum安装了。
yum -y install mysql80-community-release-el7-3.noarch.rpm
已加载插件:fastestmirror 正在检查 mysql80-community-release-el7-3.noarch.rpm: mysql80-community-release-el7-3.noarch mysql80-community-release-el7-3.noarch.rpm 将被安装 正在解决依赖关系 --> 正在检查事务 ---> 软件包 mysql80-community-release.noarch.0.el7-3 将被 安装 --> 解决依赖关系完成 依赖关系解决 ============================================================================================================================================================== Package 架构 版本 源 大小 ============================================================================================================================================================== 正在安装: mysql80-community-release noarch el7-3 /mysql80-community-release-el7-3.noarch 31 k 事务概要 ============================================================================================================================================================== 安装 1 软件包 总计:31 k 安装大小:31 k Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装 : mysql80-community-release-el7-3.noarch 1/1 验证中 : mysql80-community-release-el7-3.noarch 1/1 已安装: mysql80-community-release.noarch 0:el7-3 完毕!
安装mysql 服务器
yum -y install mysql-community-server
这步可能会花些时间,安装完成后就会覆盖掉之前的mariadb。
已安装: mysql-community-libs.x86_64 0:8.0.20-1.el7 mysql-community-libs-compat.x86_64 0:8.0.20-1.el7 mysql-community-server.x86_64 0:8.0.20-1.el7 作为依赖被安装: mysql-community-client.x86_64 0:8.0.20-1.el7 mysql-community-common.x86_64 0:8.0.20-1.el7 net-tools.x86_64 0:2.0-0.25.20131004git.el7 作为依赖被升级: postfix.x86_64 2:2.10.1-9.el7 替代: mariadb-libs.x86_64 1:5.5.64-1.el7 完毕!
2 MySQL数据库设置
首先启动MySQL
systemctl start mysqld.service
查看MySQL状态
[ home]# systemctl start mysqld.service [ home]# systemctl status mysqld.service
● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 四 2020-04-30 08:39:23 CST; 3min 28s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 50681 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 50792 (mysqld) Status: "Server is operational" Tasks: 38 Memory: 420.6M CGroup: /system.slice/mysqld.service └─50792 /usr/sbin/mysqld 4月 30 08:38:42 localhost systemd[1]: Starting MySQL Server... 4月 30 08:39:23 localhost systemd[1]: Started MySQL Server.
此时MySQL已经开始正常运行,不过要想进入MySQL还得先找出此时root用户的密码,通过如下命令可以在日志文件中找出密码:
[ home]# grep "password" /var/log/mysqld.log 2020-04-30T00:38:58.704393Z 6 [Note] [MY-010454] [Server] A temporary password is generated for : ******
如下命令进入数据库:
[ home]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.20 Copyright (c) 2000, 2020, 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默认必须修改密码之后才能操作数据库:
ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘new password‘;
这里有个问题,新密码设置的时候如果设置的过于简单会报错:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
原因是因为MySQL有密码设置的规范,具体是与validate_password_policy的值有关:
MySQL完整的初始密码规则可以通过如下命令查看:
mysql> SHOW VARIABLES LIKE ‘validate_password%‘; +--------------------------------------+-------+ | Variable_name | Value | +--------------------------------------+-------+ | validate_password_check_user_name | OFF | | validate_password_dictionary_file | | | validate_password_length | 4 | | validate_password_mixed_case_count | 1 | | validate_password_number_count | 1 | | validate_password_policy | LOW | | validate_password_special_char_count | 1 | +--------------------------------------+-------+ rows in set (0.01 sec)
密码的长度是由validate_password_length决定的,而validate_password_length的计算公式是:
validate_password_length = validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)
我的是已经修改过的,初始情况下第一个的值是ON,validate_password_length是8。可以通过如下命令修改:
mysql> set global validate_password_policy=0; mysql> set global validate_password_length=1;
设置之后就是我上面查出来的那几个值了,此时密码就可以设置的很简单,例如1234之类的。到此数据库的密码设置就完成了。
但此时还有一个问题,就是因为安装了Yum Repository,以后每次yum操作都会自动更新,需要把这个卸载掉:
yum -y remove mysql80-community-release-el7-3.noarch
此时才算真的完成了。
如果在密码设置那里不想改,直接将密码设置成比较复杂的密码 大写+小写+特殊字符+数字 即可
相关推荐
Gexrior 2020-10-22
CoderToy 2020-11-16
emmm00 2020-11-17
王艺强 2020-11-17
ribavnu 2020-11-16
bianruifeng 2020-11-16
wangshuangbao 2020-11-13
苏康申 2020-11-13
vivenwan 2020-11-13
moyekongling 2020-11-13
云中舞步 2020-11-12
要啥自行车一把梭 2020-11-12
aydh 2020-11-12
kuwoyinlehe 2020-11-12
minerk 2020-11-12
vitasfly 2020-11-12
jazywoo在路上 2020-11-11
敏敏张 2020-11-11