前言:
由于centos7开始,默认的数据库软件已经变为了mariadb,并且移除了mysql安装源
1.[root@localhost lcr]# rpm -qa | grep mariadb
2.[lcr@localhost ~]$ rpm -qa | grep mariadb
3.mariadb-5.5.52-1.el7.x86_64
4.mariadb-libs-5.5.52-1.el7.x86_64
5.mariadb-devel-5.5.52-1.el7.x86_64
6.mariadb-server-5.5.52-1.el7.x86_64
7.[root@localhost lcr]# yum remove mariadb-libs.x86_64
1.[root@localhost lcr]# yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
官方源可能速度太慢了,可以更换
中科大镜像源
1.[root@localhost lcr]# yum localinstall http://mirrors.ustc.edu.cn/mysql-repo/mysql57-community-release-el7-11.noarch.rpm
1.yum repolist enabled | grep "mysql.*-community.*"
1.[root@localhost ~]# yum repolist enabled | grep "mysql.*-community.*"
2.mysql-connectors-community/x86_64 MySQL Connectors Community 42
3.mysql-tools-community/x86_64 MySQL Tools Community 51
4.mysql57-community/x86_64 MySQL 5.7 Community Server 207
vim /etc/yum.repos.d/mysql-community.repo
选择要安装的community版本,将:
enabled=0
改为enabled=1
,其余改为enabled=0
1.[root@localhost ~]# vim /etc/yum.repos.d/mysql-community.repo
2.[mysql-connectors-community]
3.name=MySQL Connectors Community
4.baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
5.enabled=1
6.gpgcheck=1
7.gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
8.[mysql-tools-community]
9.name=MySQL Tools Community
10.baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
11.enabled=1
12.gpgcheck=1
13.gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
14.# Enable to use MySQL 5.5
15.[mysql55-community]
16.name=MySQL 5.5 Community Server
17.baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
18.enabled=0
19.gpgcheck=1
20.gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
21.# Enable to use MySQL 5.6
22.[mysql56-community]
23.name=MySQL 5.6 Community Server
24.baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
25.enabled=0
26.gpgcheck=1
27.gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
28.[mysql57-community]
29.name=MySQL 5.7 Community Server
30.baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
31.enabled=1
32.gpgcheck=1
33.gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
34.[mysql80-community]
35.name=MySQL 8.0 Community Server
36.baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
yum install mysql-community-server
1.[root@localhost ~]# yum install mysql-community-server
rpm -qa |grep mysql
1.[root@centOS ~]# rpm -qa |grep mysql
2.mysql-community-client-5.7.19-1.el7.x86_64
3.mysql57-community-release-el7-11.noarch
4.mysql-community-server-5.7.19-1.el7.x86_64
5.mysql-community-common-5.7.19-1.el7.x86_64
6.mysql-community-libs-5.7.19-1.el7.x86_64
systemctl start mysqld
1.[root@localhost ~]# systemctl start mysqld
systemctl status mysqld
1.[root@localhost ~]# systemctl status mysqld
2.● mysqld.service - MySQL Community Server
3.Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
4.Active: active (running) since 四 2017-08-31 14:31:18 CST; 29s ago
5.Process: 14957 ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=0/SUCCESS)
6.Process: 14936 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
7.Main PID: 14955 (mysqld_safe)
8.CGroup: /system.slice/mysqld.service
9.├─14955 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
10.└─15121 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir...
11.8月 31 14:31:15 localhost.localdomain systemd[1]: Starting MySQL Community Server...
12.8月 31 14:31:16 localhost.localdomain mysqld_safe[14955]: 170831 14:31:16 mysqld_safe ....
13.8月 31 14:31:16 localhost.localdomain mysqld_safe[14955]: 170831 14:31:16 mysqld_safe ...l
14.8月 31 14:31:18 localhost.localdomain systemd[1]: Started MySQL Community Server.
15.Hint: Some lines were ellipsized, use -l to show in full.
systemctl enable mysqld
systemctl daemon-reload
1.[root@centOS ~]# systemctl enable mysqld
2.[root@centOS ~]# systemctl daemon-reload
nano /var/log/mysqld.log
1.[root@centOS ~]# nano /var/log/mysqld.log
2.2017-08-31T11:00:12.326998Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
3.2017-08-31T11:00:14.118974Z 0 [Warning] InnoDB: New log files created, LSN=45790
4.2017-08-31T11:00:14.210958Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
5.2017-08-31T11:00:14.270194Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 90dced13-8e3b-11e7-a3f5-000c2$
6.2017-08-31T11:00:14.271751Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
7.2017-08-31T11:00:14.272562Z 1 [Note] A temporary password is generated for root@localhost: kl<T=kws0;3x
- A temporary password is generated for root@localhost:
kl<T=kws0;3x
这就是初始密码- 注意:如果此日志为空,可以先运行:mysql -uroot -p,然后随意输入错误的密码,再运行上面的步骤
mysql -uroot -p
1.[root@centOS log]# mysql -uroot -p
2.Enter password: <------输入上面的初始化密码
1.Welcome to the MySQL monitor. Commands end with ; or \g.
2.Your MySQL connection id is 7
3.Server version: 5.7.19
4.Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
5.Oracle is a registered trademark of Oracle Corporation and/or its
6.affiliates. Other names may be trademarks of their respective
7.owners.
8.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
9.mysql> set password for 'root'@'localhost'=password('775120Zhxxxxxx');
10.ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
11.mysql> set password for 'root'@'localhost'=password('775120@Zhxxxxxxx');
12.Query OK, 0 rows affected, 1 warning (0.00 sec)
13.mysql> exit
14.Bye
注意:
5.7
版本开始的,增加了密码强壮度度检测模块,要求密码包含数字
,大小写字母
,字符
mysql_secure_installation
1.[root@centOS ~]# mysql_secure_installation
2.Securing the MySQL server deployment.
3.Enter password for user root:
4.The 'validate_password' plugin is installed on the server.
5.The subsequent steps will run with the existing configuration
6.of the plugin.
7.Using existing password for root.
8.Estimated strength of the password: 100
9.Change the password for root ? ((Press y|Y for Yes, any other key for No) : <--------是否修改密码
10.... skipping.
11.By default, a MySQL installation has an anonymous user,
12.allowing anyone to log into MySQL without having to have
13.a user account created for them. This is intended only for
14.testing, and to make the installation go a bit smoother.
15.You should remove them before moving into a production
16.environment.
17.Remove anonymous users? (Press y|Y for Yes, any other key for No) : y <------------是否删除匿名账户
18.Success.
19.Normally, root should only be allowed to connect from
20.'localhost'. This ensures that someone cannot guess at
21.the root password from the network.
22.Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y <----------禁止远程登录
23.Success.
24.By default, MySQL comes with a database named 'test' that
25.anyone can access. This is also intended only for testing,
26.and should be removed before moving into a production
27.environment.
28.Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y <----------删除测试数据
29.- Dropping test database...
30.Success.
31.- Removing privileges on test database...
32.Success.
33.Reloading the privilege tables will ensure that all changes
34.made so far will take effect immediately.
35.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y <--------重新加载权限表
36.Success.
37.All done!
至此,centos7下,MySQL安装完毕
点击回到fatcat的主页