Mysql學習---基礎操作學習

來源:互聯網
上載者:User

標籤:原子性操作   建立檔案   ati   mysqld   插入資料   萬用字元   事務   ase   localhost   

1.1. 基本操作

資料庫引擎

Inodb:支援事務[原子性操作,完成一些列操作後才算完成操作,否則rollback]

MyISAM: 支援全文索引,強調了快速讀取操作,主要用於高負載的select

建立資料庫,表:

show databases;  # 查看當前Mysql都有那些資料,根目錄都有那些檔案夾create datab  ase 資料庫名;  # 建立檔案夾use 資料庫名;  # 使用選中資料庫,進入目錄show tables;  # 查看當前資料庫下都有那些表create table 表名(nid int, name varchar(20), pwd varchar(64));  # 建立資料庫表select * from 表名;  # 查看錶中的所有資料insert into 表名(nid, name, pwd) values(1, ‘alex‘, ‘123‘);  # 插入資料select * from 表名 where id = 1;

使用者管理特殊命令:

建立使用者create user ‘使用者名稱‘@‘IP地址‘ identified by ‘密碼‘;create user ‘hhh‘@‘192.168.25.%‘ identified by ‘777‘;  # 遠端連線 %表示萬用字元刪除使用者drop user ‘使用者名稱‘@‘IP地址‘; 修改使用者rename user‘使用者名稱‘@‘IP地址‘ to ‘新使用者名稱‘@‘IP地址‘;修改密碼set password for ‘使用者名稱‘ @ ‘IP地址‘ = Password(‘新密碼‘)flush privileges;  # 命令即時生效

許可權管理:預設無

show grants for [email protected]; # 查看許可權grant all privileges on mysql.test to [email protected]ocalhost; # 授權grant all privileges on mysql.user  to [email protected]‘192.168.25.%‘;# 遠程授權revoke all privileges on mysql.test from [email protected]; # 收權flush privileges;  # 命令即時生效

遠端連線:

mysql -u root -h 192.168.25.100 -P 3306 –p

資料庫層級操作:

SHOW DATABASES;CREATE DATABASE 資料庫名稱;CREATE DATABASE 資料庫名稱 DEFAULT CHARSET utf8 COLLATE utf8_general_ci;USE 資料庫名稱;drop database 資料庫名稱;

表層級操作:

show tables; desc tb1;drop table hhh;  # 刪除表delete from hhh where id = 1; # 清空表內容truncate table hhh; # 清空表,但是保留表的架構select * from hhh;update hhh set sex = ‘m‘ where id = 1;create table hhh (    id  int,    name varchar(12),   sex  varchar(2))

忘記密碼:

# 啟動免授權服務端mysqld --skip-grant-tables# 用戶端mysql -u root -p# 修改使用者名稱密碼update mysql.user set authentication_string=password(‘666‘) where user=‘root‘;flush privileges;

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.