mysql安装

mysql数据库的安装

1、【5.7版本】

# wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm

安装 yum repo文件

# yum localinstall mysql80-community-release-el7-1.noarch.rpm

查看 YUM 仓库关于 MySQL 的所有仓库列表

# yum repolist all | grep mysql

只查看启用的

# yum repolist enabled | grep mysql

安装 YUM 管理工具包,此包提供了 yum-config-manager 命令工具

# yum install yum-utils

禁用 8.0

# yum-config-manager --disable mysql80-community

启用 5.7

# yum-config-manager --enable mysql57-community

或手动修改

# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=1   # 这里改为 1, 当然其他的版本就需要改为 0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

再次确认启用的 MySQL 仓库

yum repolist enabled | grep mysql

开始安装 MySQL

# yum install -y  mysql-community-server

启动

# systemctl start mysqld.service

查看状态

# systemctl status mysqld.service

开机自启动

# systemctl enable mysqld.server

查看监听端口,默认 3306

#  ss -natl |grep 3306

查看原有密码

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

修改密码

mysqladmin -p'原密码' password  '新密码'

2、【8.0版本】

先清掉之前装的mysql的环境

[root@rpm-mysql ~]# rpm -qa |grep -i mysql
mysql80-community-release-el7-2.noarch
[root@rpm-mysql ~]# yum history undo 9
[root@rpm-mysql ~]# rpm -e mysql80-community-release
[root@rpm-mysql yum.repos.d]# rm -rf /var/lib/mysql/
[root@rpm-mysql yum.repos.d]# rm -rf /etc/my.cnf

安装mysql

[root@server mysql]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.14-1.el7.x86_64.rpm-bundle.tar
[root@rpm-mysql ~]# tar xf mysql-8.0.14-1.el7.x86_64.rpm-bundle.tar 
[root@rpm-mysql ~]# yum -y install net-tools
[root@rpm-mysql ~]# rpm -ivh mysql-community-server-8.0.14-1.el7.x86_64.rpm  mysql-community-client-8.0.14-1.el7.x86_64.rpm mysql-community-common-8.0.14-1.el7.x86_64.rpm  mysql-community-libs-8.0.14-1.el7.x86_64.rpm 

启动服务

[root@xiaochen ~]# systemctl  restart mysqld 
[root@xiaochen ~]# systemctl  enable mysqld
[root@node01 ~]# ss -antp | grep "mysqld"
LISTEN     0      80          :::3306                    :::*                   users:(("mysqld",pid=2293,fd=22))

=====================修改密码===================================
获取root用户的临时密码,并修改

[root@node01 ~]# grep "password" /var/log/mysqld.log 
2017-03-09T05:48:24.711787Z 1 [Note] A temporary password is generated for root@localhost: >DK+,(%2qNl&
2017-03-09T05:51:32.429509Z 3 [Note] Access denied for user 'root'@'localhost' (using password: NO)

修改root用户密码方法1:

# mysql -u root -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Www.1.com';         
mysql> FLUSH PRIVILEGES;                                            >>>>刷新授权表
mysql> exit

修改root用户密码方法2:

[root@node01 ~]# mysqladmin -u root -p password "Www.2.com"
Enter password: 

实验环境不知道root密码的操作方法如下

[root@xiaochen day4]# systemctl  stop mysqld
[root@xiaochen day4]# rm -rf /var/lib/mysql
[root@xiaochen day4]# systemctl  restart mysqld
[root@xiaochen day4]# grep password /var/log/mysqld.log
2017-08-04T03:31:32.983327Z 1 [Note] A temporary password is generated for root@localhost: krqK<_wQg8RF
[root@xiaochen day4]# mysql -p
Enter password: 

生产环境不知道root密码的操作如下:

[root@xiaochen ~]# systemctl stop mysqld
[root@xiaochen ~]# vim /etc/my.cnf
skip-grant-tables
[root@xiaochen ~]# systemctl  restart mysqld
[root@xiaochen ~]# mysql
mysql> update mysql.user set authentication_string='' where user='root' and Host='localhost';
mysql> flush privileges;
mysql> select user,authentication_string,host,password_expired from mysql.user;
[root@xiaochen 7]# vim /etc/my.cnf
#skip-grant-tables
[root@xiaochen 7]# systemctl restart mysqld

将mysql的密码重置为空之后,重新修改mysql的密码

[root@mysql ~]# mysqladmin -uroot -p password "Www1.baidu.com"

你可能感兴趣的:(mysql安装)