MySQL数据库使用——MySQL数据库管理

开发时一般不使用系统的root用户,应该是创建一个新的用户,管理一个工程。
登录用户的命令:mysql -uusername -p

登录完成后就进入SQL命令格式,格式以“;”结尾。

登录系统用户

windows用安装的时候设置的root登录命令行,如下图所示。
这里写图片描述

Linux安装时若没有提示设置root密码的,可以使用系统默认的账号和密码。
账号密码在文件/etc/mysql/debian.cnf中

ghost@ghost-machine:~$ sudo cat /etc/mysql/debian.cnf
[sudo] ghost 的密码: 
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = j0oQ******ZmV
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = j0oQ******ZmV
socket   = /var/run/mysqld/mysqld.sock
ghost@ghost-machine:~$
ghost@ghost-machine:~$ mysql -udebian-sys-maint -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.19-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2017, 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>

创建数据库:CREATE DATABASE

创建的数据库为基本数据库,根据各个项目名来创建这个项目下用到的数据库类型。数据库的管理只能是本地登录的管理员用户进行管理,不能通过远程进行管理。

SQL命令:

create database zx_mysql;
mysql> create database zx_mysql;
Query OK, 1 row affected (0.02 sec)

mysql>

显示数据库:SHOW DATABASE

SQL命令:

show databases;
mysql> show databases;
+---------------------------+
| Database                  |
+---------------------------+
| information_schema        |
| mysql                     |
| performance_schema        |
| sys                       |
| zx_mysql                  |
+---------------------------+
6 rows in set (0.00 sec)

mysql>

删除数据库:DROP DATABASE

SQL命令:

drop database zx_mysql;
mysql> drop database zx_mysql;
Query OK, 0 rows affected (0.19 sec)

mysql>

使用与跳转数据库:USE DATABASE

SQL命令:

use database zx_mysql;
mysql> use zx_mysql;
Database changed
mysql>

猜你喜欢

转载自blog.csdn.net/zxng_work/article/details/78822406