mysql基本命令

來源:互聯網
上載者:User

標籤:mysql忘記密碼   基本sql語句   

登入mysql

mysql -p 輸入密碼登入

1、查看mysql版本

mysql > select version();或者是你登入進mysql 的時候會有一大段輸出資訊,那裡也包含版本資訊

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/6C/6D/wKioL1VJjYGBo9gHAAKnIvdNebM995.jpg" title="QQ20150506113646.png" alt="wKioL1VJjYGBo9gHAAKnIvdNebM995.jpg" />

2、查看當前登入到mysql的使用者

mysql > select user();

3、查看當前資料庫中有哪些使用者

mysql > select user from mysql.user;

4、查看當前資料庫中有哪些使用者、host和密碼

mysql > select user,host,password from mysql.user;

5、查看123456加密後的字串是什麼

mysql > select password(‘123456‘);

6、修改root密碼 這裡設定為123456

mysql > use mysql;

mysql > update user set password=password(‘123456‘) where user=‘root‘;

7、如果忘記root密碼,重啟mysql加參數--skip-grant-tables 可以免密碼登入

# service mysqld stop  停掉mysql服務

# /usr/bin/mysqld_save --skip-grant-tables &  以命令列參數啟動mysql

# mysql   進入資料庫執行6的操作修改密碼

8、建立字元集是utf8的資料庫

mysql > create database ceshi character set utf8;

9、建立使用者管理資料庫

mysql > grant all privileges on ceshi.* to ‘ceshi‘@‘%‘ identified by ‘123456‘;

10、建立表

mysql > create table test (id int(11),name varchar(16));

11、向表中插入資料

mysql > insert into test valuses (1,‘xiaohong‘);

批量插入

mysql > insert into test valuses (2,‘xiaoli‘),(3,‘hanmei‘);

12、添加、修改、刪除欄位格式

mysql  >  ALTER TABLE table_name ADD field_name field_type; 添加欄位

mysql > ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;修改原欄位名稱及類型

mysql > ALTER TABLE table_name DROP field_name;刪除欄位

mysql>ALTER TABLE `user_movement_log` CHANGE `GatewayId` `GatewayId` int not null default 0 AFTER RegionID;調整列的順序

13、在id欄位前添加一個age欄位 tinyint(2)

mysql > alter table test add age tinyint(2)not Null after id;

14、刪除age欄位

mysql > alter table test drop column age;

15、查看某個資料庫大小

怎樣用命令查看Mysql資料庫大小

  1、進去指定schema 資料庫(存放了其他的資料庫的資訊)

mysql > use information_schema

  2、查詢所有資料的大小

mysql > select concat(round(sum(DATA_LENGTH/1024/1024),2),‘MB‘) as data  from TABLES

  3、查看指定資料庫的大小

  比如說 資料庫apoyl

mysql > select concat(round(sum(DATA_LENGTH/1024/1024),2),‘MB‘) as data  from TABLES where table_schema=‘apoyl‘;

  4、查看指定資料庫的表的大小

  比如說 資料庫apoyl 中apoyl_test表

mysql > select concat(round(sum(DATA_LENGTH/1024/1024),2),‘MB‘) as data  from TABLES where table_schema=‘apoyl‘ and table_name=‘apoyl_test‘;

15、將test表中的order_id欄位改成decimal(30,0)這個類型

mysql > alter table test  modify order_id decimal(30,0) unsigned NULL;   

16、查看哪些線程正在運行

mysql > show  processlist;

17、

mysql >  show engines;看你的mysql現在已提供什麼儲存引擎:
mysql > show variables like ‘%storage_engine%‘;看你的mysql當前預設的儲存引擎:
mysql > show variables like ‘%slow%‘;  查看慢查詢日誌路徑及是否開啟

本文出自 “煥然一新” 部落格,請務必保留此出處http://4374568.blog.51cto.com/4364568/1642439

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.