安装 MySQL
sudo apt update
sudo apt upgrade
sudo apt install mysql-server
装完后,预设 root 没有 password 要用 sudo mysql 登陆 注: 经过 auth_socker 验证
然后,先做一些基本配置 ?
sudo mysql_secure_installation
然后,建立数据库和新用户
sudo mysql
create user 'invent_dba'@'%' identified by 'invent_dba_password';
create database invent;
grant all on invent.* to 'invent_dba'@'%';
select user, host from user;
mysql> select user, host from user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| invent_dba | % |
| debian-sys-maint | localhost |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
6 rows in set (0.00 sec)
flush privileges;
然后,新用户登陆一下试试
$ mysql -u invent_dba -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.26-0ubuntu0.20.04.2 (Ubuntu)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| invent |
+--------------------+
2 rows in set (0.00 sec)
|