Ubuntu20.04下安装并使用MySQL8.0(Ubuntu20. 04 install and use mysql8 0)

安装

sudo apt install mysql-server-8.0

安装后需启用MySQL

sudo service mysql start

配置Ubuntu下安装mysql8.0之后,默认root用户是没有密码的,可以使用如下命令直接进入MySQL

sudo mysql -uroot

设置root密码

mysql> use mysql;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
mysql>flush privileges;
mysql> quit;

重启MySQL服务

sudo service mysql restart

连接MySQL

完成上面的步骤之后,就可以使用下面的命令来登录MySQL了。

sudo mysql -uroot -p
————————

install

sudo apt install mysql-server-8.0

MySQL needs to be enabled after installation

sudo service mysql start

Install mysql8.0 under Ubuntu configuration After 0, the default root user does not have a password. You can use the following command to directly enter mysql

sudo mysql -uroot

Set root password

mysql> use mysql;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
mysql>flush privileges;
mysql> quit;

Restart MySQL service

sudo service mysql restart

Connect to MySQL

After completing the above steps, you can use the following command to log in to MySQL.

sudo mysql -uroot -p