Centos 7 安装MySQL
1.下载
获取系统版本号:uname -a
[root@hadoop-senior01 ~]# uname -a #查看版本
Linux hadoop-senior01.ibeifeng.com 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux #版本el7.x86_64
[root@hadoop-senior01 software]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm #下载mysql
[root@hadoop-senior01 software]# ls
apache-hive-0.13.1-bin.tar.gz eclipse-jee-kepler-SR1-linux-gtk-x86_64.tar.gz mysql57-community-release-el7-8.noarch.rpm
apache-hive-0.13.1-src.tar.gz hadoop-2.5.0.tar.gz native-2.5.0.tar.gz
apache-maven-3.0.5-bin.tar.gz jdk-8u144-linux-x64.tar.gz
2.安装
[root@hadoop-senior01 software]# rpm -Uvh mysql57-community-release-el7-8.noarch.rpm
3.查看
(1)执行上一部后,/etc/yum.repos.d会多了两个mysql的repo文件
[root@hadoop-senior01 yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo mysql-community-source.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo mysql-community.repo
(2)查看mysql-community.repo,enabled=1代表安装的版本,我们装的是5.7
[root@hadoop-senior01 yum.repos.d]# more mysql-community.repo
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-preview]
name=MySQL Tools Preview
baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-cluster-7.5-community]
name=MySQL Cluster 7.5 Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-7.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
4.安装
root@hadoop-senior01 yum.repos.d]# yum install mysql-community-server
5.启动MySQL服务
[root@hadoop-senior01 yum.repos.d]# systemctl start mysqld
[root@hadoop-senior01 yum.repos.d]# systemctl status mysqld #查看状态
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 四 2018-01-18 09:41:47 CST; 1h 59min ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 1467 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 1022 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 1470 (mysqld)
CGroup: /system.slice/mysqld.service
└─1470 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
1月 18 09:41:21 hadoop-senior01.ibeifeng.com systemd[1]: Starting MySQL Server...
1月 18 09:41:47 hadoop-senior01.ibeifeng.com systemd[1]: Started MySQL Server.
6、设置机启动
[root@hadoop-senior01 yum.repos.d]# systemctl enable mysqld
[root@hadoop-senior01 yum.repos.d]# systemctl daemon-reload
7、修改root本地登录密码
(1)获取随机登录密码
[root@hadoop-senior01 yum.repos.d]# grep 'temporary password' /var/log/mysqld.log
2018-01-17T12:40:24.758334Z 1 [Note] A temporary password is generated for root@localhost: )PtorypW-3g: #安装后产生的随机密码:")PtorypW-3g:" 12位
(2)登录mysql修改密码
[root@hadoop-senior01 yum.repos.d]# mysql -uroot -p
Enter password: #把刚才的随机密码粘贴过来,粘贴屏幕默认不显示密码,直接回车
Welcome to the MySQL monitor. Commands end with ; or g.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; #第一次修改密码,关闭安全插件后可以改成123456
或者
mysql> set password for 'root'@'localhost'=password('MyNewPass4!');
mysql5.7默认安装了密码安全检查插件(validate_password),要求密码必须包含:大小写字母、数字和特殊符号,长度不能少于8位。/etc/my.cnf配置关闭此项。
8、配置:/etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
validate_password=off #关闭密码安全检查插件
character_set_server=utf8 #默认编码为utf8
init_connect='SET NAMES utf8' #默认编码为utf8
lower_case_table_names=1 #不区分大小写