安装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)
可我没设置密码啊,网上找了几个方式都没用。
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.
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:
Previous version,
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
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
The default password may be saved in a file
~/.mysql_secret
.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