Article directory
-
- foreword
- text
-
-
-
- 1. Log in to MySQL first and create a user with all permissions
- 2. Refresh the permission information to make it take effect immediately
- 3. Enter the MySQL directory and modify the mysqld.cnf file
- 4. Test whether you can connect to MySQL on the local server
- 5. Turn off the server firewall
- 6. Open port 3306 of the Alibaba Cloud console
- 7. Test the connection again
-
-
- Summarize
foreword
Today, I wanted to remotely connect to MySQL in Alibaba Cloud Ubuntu, but after configuring it according to the online tutorial, there was still some problem, so I found the problem and recorded it myself.
text
1. Log in to MySQL first and create a user with all permissions
GRANT ALL PRIVILEGES ON *.* TO '用户名'@'%'
IDENTIFIED BY '用户密码' WITH GRANT OPTION;
2. Refresh the permission information to make it take effect immediately
FLUSH PRIVILEGES;
3. Enter the MySQL directory and modify the mysqld.cnf file
When entering the MySQL directory, we found a my.cnf file (window is like my.ini).
After clicking, we found that there was very little content in it, but there were two lines of code at the end, which roughly means to introduce external files.
We open mysql according to its instructions. .conf.d directory, found that there is a mysqld.cnf file, this is the file we need to modify!
It is recommended that you copy the source file before modifying each configuration file. If the modification is wrong, you can use the copied file to replace the modified file to avoid the problem becoming bigger!
The red circle is the file we want to modify, the blue circle is the copy I copied to
modify mysqld.cnf, find bind-address=127.0.0.1, comment it, and add bind-address=0.0.0.0
4. Test whether you can connect to MySQL on the local server
Here I am using navicat, create a new connection, select MySQL, and fill in according to the following figure.
After clicking the test connection, I found that an error was reported!
I went to check Baidu, and then it may be because the firewall is turned on in Ubuntu
5. Turn off the server firewall
Check the firewall status first. If the firewall is inactive (closed), you can skip this step and go directly to step 6
sudo ufw status
If the firewall is active (open state), enter the following command to close the firewall
sudo utf disable
Test again if you can connect, or not
6. Open port 3306 of the Alibaba Cloud console
At this time, I thought of another possibility, that the port is not open, because I have written a few blogs before because of the Alibaba Cloud port problem. If you are interested, you can check my previous blog
[PHP] in Alibaba Cloud Server Ubuntu Mailbox PHPMailer has a 500 problem
[SSL] After configuring SSL, the https443 port cannot be accessed through the Alibaba Cloud server.
Log in to the Alibaba Cloud console, check the security group rules of the server, and
you can't see port 3306 (the port here is what I configured before, if it is different from what you show is normal),
add the security group rules, and fill in according to the following figure
7. Test the connection again
connection succeeded!
Summarize
When modifying the configuration file, it is recommended that you develop a good habit of backup
, Sometimes reinstalling can't solve the problem orz, doing a lot of useless work.
come on! Continue to solve one problem one by one!