標籤:mysql基本操作綜合
修改管理員命令 mysql -u root -h 192.168.44.10 -p ###-u指定使用者名稱 -h 指定主機 -p 指定密碼,一般斷行符號輸入密碼mysqladmin -u root -p password new_password 斷行符號後輸入就密碼,如果root已經設定密碼,需要使用改命令修改mysqladmin -u root -pold_password password new_password -p後面直接跟密碼update user set password=password(‘new_password‘) where user=‘root‘ and host=‘localhost‘;flush privileges update更新密碼,需要重新整理set password=password(‘new_password‘); 為root使用者修改密碼set password for ‘user_name‘@‘host_name‘=password(‘user_name‘); 為使用者‘user_name‘@‘host_name‘修改密碼查看資料庫版本等內容mysql> select version(); 查看版本資訊mysql> select now(); 查看時間mysql> select dayofmonth(current_date); 顯示年月日mysql> select (9+9)-10; 數學運算資料庫的切換,查看,建立,刪除mysql> show databases; 查看當前所有資料庫mysql> create database new_database; 建立資料庫mysql> create database if not exists database_name; if not exist 如果不存在,則建立mysql> drop database new_database; 刪除資料庫mysql> drop database if exists database_name ; if exist 判斷資料庫是否存在mysql> use mysql; 切換到mysql資料庫中mysql> rename old_database to new_database;發現這條命令在MySQL 5.1.7的時候被添加進來,5.1.23的時候又被去掉了表的查看,建立,刪除,新增內容,修改,刪除;新增欄位,修改,刪除,mysql> show tables; 查看當前資料庫中所有表mysql> desc new_table; 查看錶中的欄位類型mysql> create table new_table (id char(4),named char(10),num int(4)); 建立表,必須同時指定資料類型mysql> create table new1_table like new_table; 建立表,只是欄位,沒有內容mysql> create table new2_table select user,name from new1_table; 選擇模式建立的表,某些預設屬性等都不存在mysql> drop table new_table; 刪除表mysql> rename table new_table to new; 表的重新命名mysql> drop database if exists drop_database;//if exists 判斷資料庫是否存在,不存在也不產生錯誤mysql> insert into new_table values (‘1‘,‘ddh‘,‘100‘); 新增內容 (格式:insert into table_name values (......))mysql> insert into new_table (named,num) values (‘username‘,‘101‘); 插入部分欄位內容mysql> update new_table set named=‘ddh‘ where num=‘100‘; 修改更新內容 (格式:update table_name set ‘ ‘=‘ ‘ where ......)mysql> delete from new_table where named=‘king‘; 刪除某行內容 (格式:delete from table_name where ...........)mysql> alter table new_table add xingbie int(4) default‘0‘; 增加一個欄位 (格式:alter table_name add|change|drop ....)mysql> alter table new_table change id idd char(4) default ‘0‘; 某欄位的修改mysql> alter table new_table drop num; 刪除num欄位mysql> alter table new_table rename to tb_name; 修改表名為tb_namerename table testcourses to test;使用者新增,刪除,授權與回收(grant 授權)mysql> create user ‘king‘@‘%‘ identified by ‘king‘; 使用者新增 (格式:create user ‘ ‘@‘ ‘ identified by ‘ ‘)mysql> drop user ‘king‘@‘%‘; 使用者刪除(_匹配任意單個字元172.17.0._,%匹配任一字元) (格式:drop user ‘ ‘@‘ ‘)mysql> show grants; 查看自己的許可權 mysql> show grants for ‘king‘@‘localhost‘; 查看使用者‘king‘@‘localhost‘的許可權mysql> grant create,insert,update,delete on mysql.* to ‘king‘@‘localhost‘; 資料庫授權 (格式:grant .......on ....... to ........identified by ........)mysql> grant create,insert,update,delete on mysql.* to ‘king‘@‘localhost‘ identified by ‘hello‘; 資料庫授權並修改密碼mysql> revoke INSERT, UPDATE, DELETE, CREATE ON `mysql`.* from ‘king‘@‘localhost‘; 許可權回收 (格式: ......on .......from ............)
本文出自 “anka” 部落格,請務必保留此出處http://anka0501.blog.51cto.com/10129669/1637215
MySQL之二:基本操作(綜合詳解)