MySQL 安装使用

安装

$ sudo apt install mysql-server

使用

为 root 用户设置密码

$ sudo mysql
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
mysql> FLUSH PRIVILEGES;
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
mysql> exit

创建用户

$ mysql -u root -p
mysql> CREATE USER 'admin'@'localhost' IDENTIFIED BY '123456';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;
mysql> exit

查看数据库与表

$ mysql -u root -p
mysql> show databases;
mysql> use mysql
Database changed
mysql> show tables;
mysql> describe servers;
mysql> exit

创建数据库

$ mysql -u root -p
mysql> create database gofly;
Query OK, 1 row affected (0.04 sec)
mysql> CREATE USER 'gofly'@'localhost' IDENTIFIED BY '123456';
mysql> GRANT ALL PRIVILEGES ON gofly.* TO 'gofly'@'localhost' IDENTIFIED BY '123456';
mysql> exit

导入数据库

$ mysql -u root -p gofly < deploy/gmanager.sql
$ mysql -u root -p
mysql> use gofly
mysql> show tables;

导出数据库

$ mysqldump -u root -p gofly > dump.sql

参考资料

How To Install MySQL on Ubuntu 18.04

https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-18-04

Getting Information About Databases and Tables

https://dev.mysql.com/doc/refman/5.5/en/getting-information.html

Creating and Selecting a Database

https://dev.mysql.com/doc/refman/5.5/en/creating-database.html

How To Import and Export Databases in MySQL or MariaDB

https://www.digitalocean.com/community/tutorials/how-to-import-and-export-databases-in-mysql-or-mariadb


最后修改于 2019-07-10