This topic summarizes common issues encountered during MySQL database deployment and their corresponding solutions. It helps users smoothly install, configure, and manage MySQL databases to ensure stable server operation.
What do I do if I forget MySQL user passwords?
If you forget the password of a regular user, log on to the MySQL instance as the root user to directly modify the user password. If you forget the root user password, stop the MySQL service, start MySQL by skipping permission verification, and then reset the password.
Password for a regular user
Query the
Hostvalue of the target user.# Replace the value with the actual username. mysql -uroot -p -e "SELECT Host FROM mysql.user WHERE User = 'target_username';"Modify the password based on the
Hostvalue. If you have multiple hosts, specify each host individually.# Replace values with the actual username, password, and Host value. mysql -uroot -p -e "ALTER USER 'target_username'@'target_Host' IDENTIFIED BY 'new_password'; FLUSH PRIVILEGES;"
Root user password
Resetting the root user password requires stopping the MySQL service.
Stop the MySQL service.
Alibaba Cloud Linux or CentOS
sudo systemctl stop mysqldUbuntu or Debian
sudo systemctl stop mysqlStart MySQL in temporary mode. Record the process ID (PID) for later termination.
Note--skip-grant-tables: Skip permission verification, which allows logon without a password.&: Run the MySQL process in the background. The terminal returns a PID For example, when[1] 1234is returned,1234indicates the PID.
sudo -u mysql mysqld --skip-grant-tables &Reload the authorization tables on the server and modify the root password. Replace
<password>with the password you want to use. The password must comply with the following requirements: It must contain at least one uppercase letter, one lowercase letter, one digit, and one special character and be at least 8 characters in length.mysql -uroot -e"FLUSH PRIVILEGES;" -e"ALTER USER 'root'@'localhost' IDENTIFIED BY '<password>';"If the
Your password does not satisfy the current policy requirementserror message is returned, your password does not meet the policy requirements. You need to close the MySQL process, start MySQL by skipping permission verification, and then run the password modification command.Terminate the MySQL process.
kill <process_ID>Start the MySQL service based on the operating systems.
Alibaba Cloud Linux or CentOS
sudo systemctl start mysqldUbuntu or Debian
sudo systemctl start mysqlEnter the new password. If you can enter the MySQL CLI, the password is changed as expected.
mysql -u root -p
How do I change the MySQL data directory?
To change the MySQL data directory, perform the following steps:
Stop MySQL. The command varies based on the operating system.
Alibaba Cloud Linux or CentOS
sudo systemctl stop mysqldUbuntu or Debian
sudo systemctl stop mysqlOpen the
my.cnfconfiguration file and change thedatadirparameter in the file to the path of the new MySQL data directory. The file is usually stored in the/etc/my.cnfdirectory.datadir=/new/data/directoryCopy all files and folders in the original data directory to the new one.
sudo cp -aR /old/data/directory/* /new/data/directory/Start MySQL. The command varies based on the operating system.
Alibaba Cloud Linux and CentOS
sudo systemctl start mysqldUbuntu and Debian
sudo systemctl start mysql
What do I do if I cannot start MySQL due to the "Permission denied" error?
To resolve the issue, perform the following steps:
Check the error log file of MySQL to find the error message.
NoteBy default, the file is usually stored in the
/var/log/mysqld.logor/var/log/mysql/error.logdirectory.[ERROR] [MY-010092] [Server] Can't start server: can't create PID file: Permission deniedRun the following commands to check whether residual
mysqldprocesses exist and terminate the residual processes:sudo ps aux | grep mysqld sudo kill -9 <Process ID>Start MySQL. The command varies based on the operating system.
Alibaba Cloud Linux or CentOS
sudo systemctl start mysqldUbuntu or Debian
sudo systemctl start mysql
What do I do if I cannot start MySQL due to the "File './binlog.index' not found" error?
To resolve the issue, perform the following steps:
Check the error log file of MySQL to find the error message.
NoteBy default, the file is usually stored in the
/var/log/mysqld.logor/var/log/mysql/error.logdirectory.mysqld: File './binlog.index' not found (OS errno 13 - Permission denied)Check the MySQL data directory for user permission errors.
NoteBy default, the data directory is usually
/var/lib/mysql. If you change it, you must modify the related permissions.sudo ls -l /var/lib/mysql
Grant permissions:
sudo chown -R mysql:mysql <Data directory>Start MySQL. The command varies based on the operating system.
Alibaba Cloud Linux or CentOS
sudo systemctl start mysqldUbuntu or Debian
sudo systemctl start mysql