环境:
系统版本:CentOS Linux release 7.4.1708 (Core)
内核:Linux 3.10.0-693.el7.x86_64
**YUM安装mysql**
1、yum安装方式
关闭防火墙和selinux
[root@mysql-server ~]# systemctl stop firewalld
[root@mysql-server ~]# systemctl disable firewalld
永久关闭SELINUX的方式如下:
[root@mysql-server ~]# vim /etc/selinux/config
下边给出mysql的官网下载方式
拉到底
下载
[root@mysql-server ~]# yum -y install wget
[root@mysql-server ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
或者下载到本地上传到服务器
2.安装mysql的yum仓库
[root@mysql-server ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
[root@mysql-server ~]# yum -y install yum-utils
#安装yum工具包
3、配置yum源
[root@mysql-server ~]# vim /etc/yum.repos.d/mysql-community.repo
#修改如下
1表示开启,0表示关闭
或者
# yum-config-manager --enable mysql57-community
将禁用的yum源库启用
# yum-config-manager --disable mysql80-community
将启用的yum源库禁用
4、安装数据库
[root@mysql-server ~]# yum install -y mysql-community-server
启动服务
[root@mysql-server ~]# systemctl start mysqld
设置开机启动
[root@mysql-server ~]# systemctl enable mysqld
5、查找密码
密码保存在日志文件中
[root@mysql-server ~]# grep password /var/log/mysqld.log
2019-08-18T14:03:51.991454Z 1 [Note] A temporary password is generated for root@localhost: woHtkMgau9,w
6、修改密码
[root@mysql-server ~]# mysql -uroot -p'woHtkMgau9,w'
#登录
两种方式:
第一种:
mysql> alter user 'root'@'localhost' identified by 'Zw@123';
[root@mysql-server ~]# mysql -uroot -p'woHtkMgau9,w'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.27
…
mysql> alter user 'root'@'localhost' identified by 'Zw@123';
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
[root@mysql-server ~]# mysql -uroot -p'Zw@123'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.27 MySQL Community Server (GPL)
…
mysql> exit
Bye
第二种:
# mysqladmin -u root -p'旧密码' password '新密码'
注:修改密码必须大小写数字和特殊符号都有。
通过配置文件设置密码强度
[root@mysql-server ~]# vim /etc/my.cnf
#在最后添加如下内容
validate_password=off
[root@mysql-server ~]# systemctl restart mysqld
#重启mysql生效
可以用第二种方式修改为简单的密码:
[root@mysql-server ~]# mysqladmin -uroot -p'Zw@123' password 'Zw123'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure
password safety.
[root@mysql-server ~]# mysql -uroot -p'Zw@123'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.27 MySQL Community Server (GPL)
Copyright © 2000, 2019, 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> exit
Bye
下面是对mysql的一些文件进行说明
/var/lib/mysql 存放数据文件
/usr/share/mysql 用于存放字符集、语言等信息等消息。