Install mysql on Ubuntu system

                        #Ubuntu安装Mysql详细教程

Description:
Creator: csc
Time: 2023-05-13
Environment: Ubuntu18.04.4/Ubuntu22.04
Version: mysql 5.7.42/mysql8.0.33

 Ubuntu18.04 默认mysql数据库版本为 5.7.24
 Ubuntu22.04 默认mysql数据库版本为8.0.33
 执行安装命令不需要带对应版本,就可以直接安装,  以下步骤都一样。都经过了本人的亲测.!!  

The first step is to uninstall/clean up the residue

 dpkg --list|grep mysql

First unload the previous database based on the query

 sudo apt-get remove mysql-common

The second step is to install Mysql

Update the list

 sudo apt-get update

InstallMySQL

sudo apt-get install mysql-server

The commands to start and shut down mysql are as follows:

#启动: 
sudo service mysql start

#重启:
sudo  service mysql restart 

#关闭: 
sudo service mysql stop

The third step is to modify the mysql connection method and database password.

You just installed the database and are you worried about not knowing the password? Let me tell you

First of all, you need to log in to the database without a password. You must use sudo mysql -uroot -p. You can log in like this just after installation. I have tried it myself.

  sudo mysql -uroot -p

Just press Enter without entering any password. Then follow the following command to change the database connection and password. It’s
simple.

  mysql> use mysql;
  
#开启远程连接
update user set host='%' where user='root';
#修改了之后刷新以下权限
flush privileges;

#修改数据库密码.
ALTER USER 'root'@'%' identified with mysql_native_password BY '123456';
#修改了之后刷新以下权限
flush privileges;

#退出数据库
quit;

At this time, you can enter mysql normally by using mysql -u root -p normally in Linux and then entering your password.

mysql -u root -p and then enter the password to enter successfully
But you have opened port 3306. You have also changed localhost to % and you can’t connect using Navicat from outside, right?
Insert image description here

Step 4: Solve the problem that Navicat cannot connect to the database

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

Enter vi /etc/mysql/mysql.conf.d/mysqld.cnf, find bind-address, and change 127.0.0.1 to 0.0.0.0
Insert image description here

  # 点击 Esc按键  输入 <:qa!> 退出编辑模式.
 :wq

Then restart the mysql service.

#重启:
sudo  service mysql restart

Try navicat connection again. Successful, hahahaha,
Insert image description here
everyone is welcome to leave comments. If you find it useful, please like and add it to your collection.

Guess you like

Origin blog.csdn.net/qq_37120477/article/details/130653390