MySQL之二:基本操作(綜合詳解)

來源:互聯網
上載者:User

標籤: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之二:基本操作(綜合詳解)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.