安装mysql
# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum install mysql-community-server
启动mysql
service mysqld restart
设置密码
[root@YFPUNzLr ~]# mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
可我没设置密码啊,网上找了几个方式都没用。
迷茫2017-04-17 16:35:55
A valid answer found online:
The password is in the file /var/log/mysqld.log
You can use grep 'temporary password' /var/log/mysqld.log to query, or you can find it yourself in the file.
[root@YFPUNzLr ~]# grep 'temporary password' /var/log/mysqld.log
2017-02-15T14:31:05.449058Z 1 [Note] A temporary password is generated for root@localhost: 3NeI3PuNwa%j
[root@YFPUNzLr ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.17
Copyright (c) 2000, 2016, 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>
巴扎黑2017-04-17 16:35:55
I don’t know what your MySQL version and system version are. How many. If it is 5.7, there may be records in the log file.
If it is not in the log file, you can reset the password and there is no need to reinstall it.
MySQL 5.7.6 and latest versions:
vim /etc/my.cnf
# 添加下面的字段
skip-grant-tables
mysql> update user set mysql>authentication_string=PASSWORD('123456') where User='root';
mysql>flush privileges;
Previous version,
vim /etc/my.cnf
# 添加下面的字段
skip-grant-tables
mysql> use mysql;
mysql> update user set password=PASSWORD("password") where User='root';
mysql> flush privileges;
迷茫2017-04-17 16:35:55
Look at the error log, there should be a password field, followed by a string of strange things that is the password
If not, reset the password
阿神2017-04-17 16:35:55
Schrödinger’s password…
You should have set a password during installation. If you forget it, uninstall and reinstall it. If it still doesn’t work, check the mysql log to see if there are any errors. If it still doesn’t work, use Baidu MySQL Forgot Password to see how to force change
怪我咯2017-04-17 16:35:55
Mysql default root password is empty.
Log in using
mysql -u root -p
In addition, you can execute the following mysql_secure_insatllation to set the password