重新查看當前有哪些數據庫
首先打開cmd,輸入net start mysql啟動mysql服務,然后輸入mysql-hlocalhost-uroot-p回車登錄數據庫,之后就可以輸入命令了。
MySQL命令行有很多命令,其中查看有哪些數據庫,我們可以使用show databases;命令進行查看,注意分號不要忘了。
如果在此之前你使用了use mysql;語句,想再次查詢當前有哪些數據庫,仍然是使用show databases;命令,如果想跳到其他數據庫可以使用use test;進行切換,其中test為你想要切換的數據庫名。
推薦《mysql視頻教程》https://www.weixiu3721.com
在日常的網站維護和管理中,會用到非常多的SQL語句,熟練使用對網站管理有很多好處,尤其是站群管理的時候,以下為各位整理了命令行常用的MySQL命令,希望對各位有所幫助。
MySQL命令行下18個常用命令
1、顯示數據庫
show databases
顯示表
show tables;
2、創建用戶
創建root用戶密碼為123
use mysql;
grant all on*.*to root '%'identified by'123'with grant option;
commit;
3、修改密碼
grant all on*.*to xing 'localhost'identified by'123456'with grant option;
update user set password=password('newpwd')where user='xing'and host='localhost';
flush privileges;
4、創建數據庫testdb:
create database testdb;
5、預防性創建數據庫:
create database if not testdb;
6、創建表:
use testdb;
create table table1(
username varchar(12),
password varchar(20));
7、預防性創建表aaa:
create table if not exists aaa(ss varchar(20));
8、查看表結構:
describe table1;
9、插入數據到表table1:
insert into table1(username,password)values
('leizhimin','lavasoft'),
('hellokitty','hahhahah');
commit;
10、查詢表table1:
select*from table1;
11、更改數據:
update table1 set password='hehe'where username='hellokitty';
commit;
12、刪除數據:
delete from table1 where username='hellokitty';
commit;
13、給表添加一列:
alter table table1 add column(
sex varchar(2)comment'性別',
age date not null comment'年齡'
);
commit;
14、修改表結構
從查詢創建一個表table1:
create table tmp as
select*from table1;
15、刪除表table1:
drop table if exists table1;
drop table if exists tmp;
16、備份數據庫testdb
mysqldump-h 192.168.3.143-u root-p pwd-x--default-character-set=gbk>C:\testdb.sql
17、刪除數據庫testdb
drop database testdb;
18、恢復testdb數據庫https://www.weixiu3721.com
首先先建立testdb數據庫,然后用下面命令進行本地恢復
mysql-u root-pleizhimin testdb<C:\testdb.sql