1、下载mysql ,同样,跳过,----需要跟linux版本相对应
2、查看虚拟机内是否有mysql
rpm -qa|grep mysql
如果有,则需要删除mysql相关文件
* rpm -ev xxx --nodeps
3.使用本地文件在线安装数据库:
* 把mysql-community-release-el6-5.noarch.rpm传到linux根目录下
* 在根目录下执行在线安装指令
yum
localinstall mysql-community-release-el6-5.noarch.rpm
4.在线安装mysql服务
* yum
install mysql-server
注意:
1.安装中断继续重新执行指令
2.报错yum指令正在被其他应用占用:
* ps -ef | grep yum 查看正在使用yum的进程...>进程号
* 根据进程号杀死 kill -9 进程号
5.启动数据库服务:
* service mysqld start
* service mysqld status 查看数据库状态
设置开机启动
systemctl enable mysqld
systemctl daemon-reload
6. 设置mysql用户名密码:
从日志中获取初始密码:
从日志中获取随机生成的密码 [root@node1 db]# grep password /var/log/mysqld.log 2018-07-15T09:01:09.735836Z 1 [Note] A temporary password is generated for root@localhost: ViFg8pWf+,lU [root@node1 db]# mysql -uroot -pViFg8pWf+,lU 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
ALTER USER USER() IDENTIFIED BY ‘123456‘;
如果密码不符合规则,则需要修改策略
第一种、alert
mysql> ALTER USER USER() IDENTIFIED BY ‘Reid790!@#$‘; Query OK, 0 rows affected (0.00 sec) mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘Tom579#$%^&‘; #针对localhost Query OK, 0 rows affected (0.00 sec) 或者先关闭其密码策略修改 mysql> select @@validate_password_length; ERROR 1820 (HY000): Unknown error 1820 mysql> ALTER USER USER() IDENTIFIED BY ‘12345678‘; Query OK, 0 rows affected (0.00 sec) validate_password_policy有以下取值: Policy Tests Performed 0 or LOW Length 1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters 2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file 默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。
第二种:跳过授权列表skip-grant-tables
[root@node1 db]# mysql ERROR 1045 (28000): Unknown error 1045 [root@node1 db]# vim /etc/my.cnf #使用完后去掉 [mysqld] skip-grant-tables=1 重启mysql,再修改 [root@node1 db]# systemctl restart mysqld [root@node1 db]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.22 MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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> set password = PASSWORD(‘Reid4909@%&‘); ERROR 1290 (HY000): Unknown error 1290 mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘Tom579#$%^&‘; ERROR 1290 (HY000): Unknown error 1290 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> set password = PASSWORD(‘Reid4909@%&‘); ERROR 1133 (42000): mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘Tom579#$%^&‘; Query OK, 0 rows affected (0.01 sec) mysql> set password for root@localhost = password(‘123456‘); Query OK, 0 rows affected, 1 warning (0.00 sec)
第三种:使用mysql_secure_installation
[root@node1 db]# mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: Marry583@&%! The ‘validate_password‘ plugin is installed on the server. The subsequent steps will run with the existing configuration of the plugin. Using existing password for root. Estimated strength of the password: 100 Change the password for root ? ((Press y|Y for Yes, any other key for No) : y New password: Tom579#$%^& Re-enter new password: Tom579#$%^& Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y 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. 为了安全应该yes Remove anonymous users? (Press y|Y for Yes, any other key for No) : No ... skipping. Normally, root should only be allowed to connect from ‘localhost‘. This ensures that someone cannot guess at the root password from the network. 为了安全应该yes Disallow root login remotely? (Press y|Y for Yes, any other key for No) : No ... skipping. 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. 为了安全应该yes Remove test database and access to it? (Press y|Y for Yes, any other key for No) : No ... skipping. 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) : y Success. All done!
第四种:使用update
mysql> UPDATE mysql.user SET authentication_string = PASSWORD(‘Marry583@&%!‘), password_expired = ‘N‘ WHERE User = ‘root‘ AND Host = ‘localhost‘; Query OK, 1 row affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
7、设置mysql远程访问
mysql> create user ‘root‘@‘%‘ identified with mysql_native_password by ‘your password‘; Query OK, 0 rows affected (0.01 sec) mysql> grant all privileges on *.* to ‘root‘@‘%‘ with grant option; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec)
8、Navicat连接mysql,输入ip、用户名、密码,点击连接测试,提示连接成功,就可以正常使用了