關於數據庫的幾條常用操作

create database test;   創建一個爲test的數據庫


show databases;     查看有哪些數據庫


create table   test;    創建一個爲test的表


show tables  查看有哪些表


mysql -h 127.0.0.1 -utest -p123  本機測試

select Host,User,Password  from user where User='test';                查看關於test的3個信息


update user set Password = password('321') where User='test' && Host='localhost';更新test的本地密碼


update user set Password = password('321') where User='test' && Host='%'; 更新test的遠程密碼

update user set Password = password('123') where User='test';            更新test本地和遠程的密碼

create USER 'test'@'%' IDENTIFIED BY '123';                         創建一個遠程用戶test 設置密碼

GRANT all on *.* to 'test'@'%';                                給用戶賦予遠程所有權限

GRANT all on *.* to 'test'@'localhost';                        給用戶賦予本地所有權限

mysqldump -u root -p --database  test>20151231test.sql                 備份test庫

mysql -u root -p 123 <voice.sql                               輸入密碼即可


CREATE TABLE IF NOT EXISTS person ( number INT(11), name VARCHAR(255), birthday DATE );
創建表


 INSERT INTO person  VALUES(1,'qwe',19900101)
插入數據


update person set birthday='10001010' where id=1;
修改數據


flush privileges   mysql 新設置用戶或更改密碼後需用flush privileges刷新MySQL的系統權限相關表,否則會出現拒絕訪問,還有一種方法,就是重新啓動mysql服務器,來使新設置生效。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章