Ubuntu 18.08 安装mysql

时间:2021-09-25 07:46:12

1、安装mysql server

sudo apt-get install mysql-server

2、查看默认生成的密码

sudo cat debian.cnf

debian.cnf

# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = pASsYAUR2aRiaprZX
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = pASsYAUR2aRiaprZX
socket   = /var/run/mysqld/mysqld.sock

  

3、默认用户登录 

mysql -u debian-sys-maint -p

4、修改root密码   

mysql> use mysql;
mysql> update user set authentication_string=password(‘123‘) where user=‘root‘ and Host =‘localhost‘;
mysql> update user set plugin="mysql_native_password"; 
mysql> flush privileges;
mysql> quit;

5、建立 测试用户

#创建测试用户
CREATE USER ‘demor‘@‘localhost‘ IDENTIFIED BY ‘123‘;
#创建测试数据库
CREATE DATABASE demo;
#添加权限
GRANT ALL PRIVILEGES ON  demo.* to ‘demo‘@‘localhost‘ IDENTIFIED BY ‘123‘;
#添加远程访问权限
GRANT ALL PRIVILEGES ON demo.* TO ‘demo‘@‘%‘ IDENTIFIED BY ‘123‘ WITH GRANT OPTION;
#刷新
flush privileges;