Tencent cloud installs the configuration database MySQL and uses SQLyog to connect

1, The first is the one click installation and uninstallation commands of MySQL (you can choose any one to execute)
(1) Installation command

sudo apt-get install mysql (Download the latest version) 
sudo apt install mysql-server mysql-client

(2) Uninstall command: if there is a problem, reinstall MySQL for use, such as forgetting the initial password

The following commands need to be run in sequence
sudo apt-get autoremove --purge mysql-server-5.7
sudo apt-get remove mysql-server
sudo apt-get autoremove mysql-server
sudo apt-get remove mysql-common
dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P

2, How to enter MySQL and set root user and password
(1) View the initial default user name and password

sudo vim /etc/mysql/debian.cnf 

If sudo vim is prompted, the command cannot be found
Because vim is not installed, execute the following command

sudo apt-get install vim-gtk

Enter the configuration file, as shown in the figure below. The account and password are in the red box. Copy them:

(2) Log in to mysql database
User name: Debian sys maint
Password: SeQPuYJf9DEXfqb0
Execute the following command

mysql -u debian-sys-maint -p

Enter password: # paste the password to log in successfully
If you forget your password or cannot connect here, please uninstall and reinstall
(3) Set root user and password
user = root
password = root
Execute any of the following command lines, and the previous commands will take precedence

alter user 'root'@'localhost' identified with mysql_native_password by 'root';
update user set authentication_string=password('root') where user='root';
update mysql.user set authentication_string=password('root') where user='root'and Host = 'localhost';

After setting, you also need to execute the following commands to exit MySQL, log in and restart MySQL
Log out of MySQL and restart mysql. Please refer to (4) (5) common MySQL command lines for specific commands

flush privileges;

(4) Common command lines after logging in to MySQL
It should be noted that after logging in to MySQL, there should be at the end of the command line;
① Use < database name >
In MySQL, the USE statement is used to complete the jump from one database to another.

use root;

② Displays which data tables are in the database

show tables;

③ Displays which fields are defined in the data table, field type and size, primary key, constraint conditions, and whether default values are defined for the fields

desc table;

④ Exit MySQL
Log in to MySQL, set the root account password, and then use this command to exit the login

quit;

(5) Management Service - common commands used when MySQL is not logged in
If there are multiple commands, select one to execute
① Start

service mysql start
sudo systemctl start mysql.service

② Stop

service mysql stop
sudo systemctl stop mysql.service

③ Restart

service mysql restart

④ Check MySQL running status

sudo netstat -tap | grep mysql
sudo systemctl status mysql.service

⑤ mysql security configuration - setting the root password is easy to fail
Refer to another article for details, but I'm useless
https://blog.csdn.net/qq_43080036/article/details/89928725

3, Connect to Tencent cloud database using SQLyog
(1) Data you need to know before connecting
Server: ip, port (22), user name, password
Database: ip (127.0.0.1), port (3306), user name (root), password (root)
(2) Connection settings for SQLyog
If you can't connect, the password is usually incorrect. Reset the server password command

sudo passwd



Here you have successfully installed the configuration database MySQL
The following are supplementary contents, which can be used in special cases

4, Supplementary content
(1) Increase password strength check when setting password for your MySQL

set global validate_password_policy=LOW;

Specific reference: https://blog.csdn.net/wltsysterm/article/details/79649484

(2) Modify mysqld.cnf. Some users need to modify the configuration file to remotely access the cloud database
The binding address needs to be modified, but I can connect without modification
binding-address=0.0.0.0
Indicates that all client hosts (ip) can access this server. If a specific address is written, such as binding address = x.x.x.x, only the host (ip) can access the server. Note that this address is not the ip address of the current mysql server.
If several client hosts are set, it can be set as: binding address = 192.169.0.1 192.168.0.2 192.168.0.3, separated by spaces.
You can find mysqld.cnf in the following ways

adopt

cd /etc/mysql/mysql.conf.d

Enter the folder where mysqld.cnf is located

then

vi mysqld.cnf

Open the mysqld.cnf configuration file to modify the configuration file
(3) Failure after setting root password
reference resources: https://blog.csdn.net/weixin_34072159/article/details/92809594

Keywords: Database MySQL Big Data

Added by ziong on Tue, 19 Oct 2021 04:19:29 +0300