CentOS7 安装MYSQL8.0 和 PhpMyAdmin
安装MySQL8.0
1. MySQL不再通过基本操作系统映像分发或在OS存储库中可用。 因此,您需要添加MySQL的官方存储库来安装MySQL community server
rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
2. 安装MySQL 8.0
yum -y install mysql-community-server
如果你不想装MySQL8.0 ,想装MySQL5.7版本就用以下的指令
yum -y install mysql-community-server --disablerepo=mysql80-community --enablerepo=mysql57-community
3. 启动MySQL
systemctl start mysqld
4. 当服务器启动时,自动启动MySQL
systemctl enable mysqld
5.获取MySQL默认密码
cat /var/log/mysqld.log | grep -i 'temporary password'
Output:
2018-07-03T13:48:06.028068Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Rpl;PMsiw4x=
6.重置密码
mysql_secure_installation
Output:【重置新密码必须有大写,数字和符号】
Securing the MySQL server deployment. Enter password for user root: <== 输入你找到的默认密码 The existing password for the user account root has expired. Please set a new password. New password: <== Enter New Root Password Re-enter new password: <== Re-Enter New Root Password VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: No <== 不需要因为已经是high secure Using existing password for root. Change the password for root ? ((Press y|Y for Yes, any other key for No) : no <== 你已经设了密码无法再重置 ... skipping. By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : yes <== 去除默认的用户 Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : yes <== 关闭远端登入 Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : yes <== 去除test数据库 - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : yes <== 重新加载权限 Success. All done!
基于MySQL 8.0 安装PhpMyAdmin
1.由于MYSQL8.0的密码验证方式从mysql_native_password改为了caching_sha2_password。而目前为止,php的pdo和mysqli应该还是不支持的,所以必须更改MySQL8.0的密码验证方式
nano /etc/my.cnf
找到
default_authentication_plugin=caching_sha2_password
改为
default_authentication_plugin=mysql_native_password
2. 因为密码已经是sha2方式保存的,所以php以原来的方式验证肯定无法通过,所以要修改一下密码,必须登入Mysql , 输入以下的指令,然后输入你的密码
mysql -u root -p
3. 如果你的密码比较简单的话,可以把密码要求降低
set global validate_password.policy=0;
4. 设置新密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
5. 重新加载权限
FLUSH PRIVILEGES;
6.更改好密码之后,就装PhpMyAdmin
yum install -y phpmyadmin
7. 更改PhpMyAdmin在Apache的设置,否者你的phpmyadmin会有白名单登入过滤的功能
nano /etc/httpd/conf.d/phpMyAdmin.conf
Output:
Alias /PhpMyAdmin /usr/share/PhpMyAdmin [ /PhpMyAdmin 可以改成你要的名,避免暴露出来] Alias /phpmyadmin /usr/share/PhpMyAdmin [ /phpmyadmin 可以改成你要的名,避免暴露出来] <Directory /usr/share/phpMyAdmin/> AddDefaultCharset UTF-8 <IfModule mod_authz_core.c> # Apache 2.4 <RequireAny> # Require ip 127.0.0.1 #注释掉 # Require ip ::1 #注释掉 Require all granted #新添加 </RequireAny> </IfModule> <IfModule !mod_authz_core.c> # Apache 2.2 Order Deny,Allow Deny from All Allow from 127.0.0.1 Allow from ::1 </IfModule> </Directory> <Directory /usr/share/phpMyAdmin/setup/> <IfModule mod_authz_core.c> # Apache 2.4 <RequireAny> #Require ip 127.0.0.1 #注释掉 #Require ip ::1 #注释掉 Require all granted #新添加 </RequireAny> </IfModule> <IfModule !mod_authz_core.c> # Apache 2.2 Order Deny,Allow Deny from All Allow from 127.0.0.1 Allow from ::1 </IfModule> </Directory>
8. 为了提升安全的话,可以把phpmyadmin登入的机制把cookie换成http
nano /etc/phpMyAdmin/config.inc.php
$cfg['Servers'][$i]['auth_type'] = 'cookie'; 【把cookie换成http】
9. 做完全部设置后必须restart apache
systemctl restart httpd
10. 完成了!接下来你就能登入你的phpmyadmin了
http://ip or domain/phpmyadmin
Facebook评论