- 安装
sudo apt-get install mysql-server(安装过程中按提示设置root密码)
sudo apt-get install mysql-client
sudo apt-get install libmysqlclient-dev
sudo netstat -tap | grep mysql
service mysql startservice mysql restartservice mysql stop
- ubuntu命令行操作数据库
- 登录mysql数据库
(base) bryant@VM:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 119
Server version: 5.7.27-0ubuntu0.16.04.1 (Ubuntu)Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
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>
-
- 退出mysql命令行
mysql> quit
Bye或者在mysl命令行按CTR+D退出到shell界面
-
- 显示数据库列表
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| permdb |
| stocks |
| sys |
| test |
+--------------------+
7 rows in set (0.00 sec)
-
- 选中数据库
mysql> use permdb ;
Database changed
-
- 显示数据库中的所有表
mysql> show tables;
+--------------------------------+
| Tables_in_permdb |
+--------------------------------+
| auth_group |
| auth_group_permissions |
| auth_permission |
| auth_user |
| auth_user_groups |
| auth_user_user_permissions |
| django_admin_log |
| django_content_type |
| django_migrations |
| django_session |
| guardian_groupobjectpermission |
| guardian_userobjectpermission |
| perm_task |
+--------------------------------+
13 rows in set (0.00 sec)
-
- help查看可用命令
mysql> help
List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
? (?) Synonym for `help'.
clear (c) Clear the current input statement.
connect ( ) Reconnect to the server. Optional arguments are db and host.
delimiter (d) Set statement delimiter.
edit (e) Edit command with $EDITOR.
ego (G) Send command to mysql server, display result vertically.
exit (q) Exit mysql. Same as quit.
go (g) Send command to mysql server.
...
- 让MySQL服务器被远程访问
sudo vim /etc/mysql/my.cnf
-
将字符编码设置为UTF-8
sudo vim /etc/mysql/my.cnf
default-character-set=utf8
character-set-server=utf8
default-character-set=utf8
mysql> show variables like '%char%';+--------------------------+----------------------------+| Variable_name | Value |+--------------------------+----------------------------+| character_set_client | utf8 || character_set_connection | utf8 || character_set_database | utf8 || character_set_filesystem | binary || character_set_results | utf8 || character_set_server | utf8 || character_set_system | utf8 || character_sets_dir | /usr/share/mysql/charsets/ |+--------------------------+----------------------------+8 rows in set (0.00 sec)
- 设置utf8字符的另一种方法
set character_set_database=utf8;set character_set_server=utf8;