mysql 常用命令 匯總

參考閱讀


摘要

? ? 權限

  • 允許公網訪問

? ? 列操作

  • 修改列名
  • mysql 修改列屬性

? ? 其他

  • 登錄設置自動補全與utf-8編碼
  • 其他
  • 一次添加多條記錄
  • 修改表名字

?

允許公網訪問

1,修改表,登錄mysql數據庫,切換到mysql數據庫,使用sql語句查看"select host,user from user ;"

mysql -u root -pvmwaremysql>use mysql;

mysql>update user set host = '%' where user ='root';

mysql>select host, user from user;

mysql>flush privileges;

注意:最后一句很重要,目的是使修改生效.如果沒有寫,則還是不能進行遠程連接. 現在你就可以遠程連接你的數據庫了。

2,授權用戶,你想root使用密碼從任何主機連接到mysql服務器

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'?IDENTIFIED BY 'root' WITH GRANT OPTION;

flush privileges;

如果你想允許用戶root從ip為192.168.1.104的主機連接到mysql服務器

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.104'?IDENTIFIED BY 'root' WITH GRANT OPTION;

flush privileges;

?


?mysql命令:


登錄 mysql

mysql -h127.0.0.1 -uroot -p?--default-character-set=utf8 --auto-rehash

auto-rehash 為設置tab自動補充功能?

?

修改表表名

?ALTER??TABLE?table_name?RENAME?TO?new_table_name

?

建立新數據庫:

mysql>?create?database?new_db;

?

查看當前數據庫:

mysql> show databases;

?

選擇某個數據庫進行操作:

mysql> use mysql;

?

建立數據表:

mysql>?create?table?new_tb (字段設定列表);

?

查看該數據庫中有哪些表。

mysql> show tables;

?

查看某個表的結構:

mysql> describe?user;

?

查看某個表中所有的元素:

mysql>?select?*?from?user;

?

可以加上where進行過濾。

mysql>?select?*?from?user?where?username=’**’;

?

可以對某個值進行更新:

mysql>?update?wp_users?set?user_pass=’new passwd’?where?user_login=’admin’;

?

刪除數據庫或者數據表:

mysql>?drop?database?庫名;
mysql>?drop?table?表名;

清空數據表中的記錄:

mysql>?delete?from?表名;

?

修改密碼(在終端下)

mysql> mysqladmin -u用戶名 -p舊密碼?password?新密碼;

?

增加新用戶:

mysql>?grant??on?數據庫.*?to?用戶名@登錄主機 identified?by?"密碼"?;

?

新用戶只有select權限,多個權限以逗號間隔即可。
導出整個數據庫

mysqldump -u root -p wp > wp.sql

?

導入數據庫

?mysql>create?database?wp_temp;

mysql>use wp_temp;
mysql>source ~/wp.sql;

清理垃圾數據:
最好先為數據庫做一下備份。

mysql>?DELETE?FROM?wp_posts?WHERE?post_type =?'revision';
?

修改列屬性

?ALTER ? TABLE ? t1 ? MODIFY ? a ? TINYINT ? NOT ? NULL, ? CHANGE ? b ? c ? CHAR(20);?


一次添加多條記錄

INSERT INTO users(name, age)

VALUES('姚明', 25), ('比爾.蓋茨', 50), ('火星人', 600);

?

修改列名

alter table persons change id id_p integer;


實例

create table test (id integer primary key, value text); ? ?包含自增長?create table test (id int auto_increment primary key, value text);

insert into test (value) values('hxl');?

insert into test (value) values('sqlite');?

insert into test (value) values('test');?

insert into test (value) values('for');?

insert into test (value) values('linux');?

?


轉載于:https://www.cnblogs.com/wangkangluo1/archive/2012/04/12/2444973.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/274888.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/274888.shtml
英文地址,請注明出處:http://en.pswp.cn/news/274888.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

一步步創建 邊欄 Gadget(二)

相信使用上篇中創建的邊欄Gadget之后,大家會很郁悶。難道視頻窗口就那么小嗎?看起來真費勁。我能通過該Gadget看著一部電視劇。而不能夠定制自己需要的或者想要看的電視劇。 在上一篇一步步創建 邊欄 Gadget(一)中,我們…

tableau 自定義圖表_一種新的十六進制美國地圖布局的案例-Tableau中的自定義圖表

tableau 自定義圖表For whatever reason, 無論出于什么原因 maps are cool. Even though the earth has mostly been the same since those 地圖很酷 。 即使自Pangaea days, we humans make and remake maps constantly. It might be that old maps remind us of how things …

2022,前端工具鏈十年盤點

大家好,我是若川。持續組織了6個月源碼共讀活動,感興趣的可以點此加我微信 ruochuan12 參與,每周大家一起學習200行左右的源碼,共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列2021 …

var result = ![] == []; console.log(result); // 結果是?為什么?

相等操作符會對操作值進行隱式轉換后進行比較,如果一個操作值為布爾值,則在比較之前先將其轉換為數值,這里 ![] 一定是布爾值了。 http://www.csser.com/board/4f3f516e38a5ebc9780004d3轉載于:https://www.cnblogs.com/anjey/archive/2012/0…

講講volatile的作用

講講volatile的作用 講講volatile的作用254推薦一個定義為volatile的變量是說這變量可能會被意想不到地改變,這樣,編譯器就不會去假設這個變量的值了。精確地說就是,優化器在用到這個變量時必須每次都小心地重新讀取這個變量的值,…

書籍排版學習心得_為什么排版是您可以學習的最佳技能

書籍排版學習心得重點 (Top highlight)I was introduced to design in a serpentine fashion. I don’t have any formal training. Instead, I’ve learned everything through the Web, books, and by interacting with designers daily.我被介紹為蛇形設計。 我沒有任何正規…

javascript專題:如何構建自己的js庫

首先看看這個: (function(){ //運行的代碼 })(); 紅色括號里面是一個匿名函數,紅色括號是分割,表示里面的函數是一個部分,綠色的括號表示一個運算符,表示紅色括號里面的函數要運行。 相當于定義完一個匿名函數后讓它直…

若川的 2021 年度總結,彈指之間

1前言從2014年開始,每一年都會寫年度總結,已經堅持了7個年頭。7年的光陰就是彈指之間,轉瞬即逝。正如孔子所說:逝者如斯夫,不舍晝夜。回顧2014,約定2015(QQ空間日志)2015年總結&…

線框圖用什么軟件_為什么要在線框中著色?

線框圖用什么軟件I was recently involved in a debate around why some wireframes (which were definitely not UI screens) were not 100% greyscale. This got me thinking — when is it ok to use colour in wireframes, and when is it going to cause you problems fur…

Linux 內核

Linux 內核是一個龐大而復雜的操作系統的核心,不過盡管龐大,但是卻采用子系統和分層的概念很好地進行了組織。通過本專題,我們可以學習 Linux 的分層架構、內核配置和編譯、內核性能調試和 Linux 2.6 中的許多提升功能。Linux 內核組成 Linux…

給asterisk寫app供CLI調用

環境:CentOS6.2 Asterisk 1.8.7.1 一、添加源文件 復制app_verbose.c為app_testApp.c 復制app_verbose.exports為app_testApp.exports 主要是修改一些標識,編譯不會出錯就行,這里列出我進行的主要修改。 1、添加頭文件 #include "aster…

前端,校招,面淘寶,指南

大家好,我是若川。持續組織了6個月源碼共讀活動,感興趣的可以點此加我微信 ruochuan12 參與,每周大家一起學習200行左右的源碼,共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列雖然是…

qq空間網頁設計_網頁設計中負空間的有效利用

qq空間網頁設計Written by Alan Smith由艾倫史密斯 ( Alan Smith)撰寫 Negative space is a key design element that you may come across in the fields of art, architecture, interior design, landscaping and web design. Rather than serving as awkward, empty areas …

自定義異常拋法

public List<LogRec> readLogs() throws ReadDataException { try { return returnLogRec(logFileName); } catch(Exception e) { throw new ReadDataException(e); } } 轉載于:https://www.cnblogs.com/zengmiaogen/archive/2012/04/15/2450438.html

SQL SERVER服務停止和啟動命令行

停止服務: net stop mssqlserver 啟動服務: net start mssqlserver 轉載于:https://www.cnblogs.com/davidgu/archive/2010/01/06/1640466.html

Git 和 GitHub 教程——版本控制入門

大家好&#xff0c;我是若川。持續組織了6個月源碼共讀活動&#xff0c;感興趣的可以點此加我微信 ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列Learn…

matlab中的:的優先級_內容早期設計:內容優先

matlab中的:的優先級By Simone Ehrlich, Content Strategy Manager由 西蒙埃利希 &#xff0c;內容策略經理 Words are cheap. Cheaper than wires; cheaper than mocks. That doesn’t mean words aren’t important, just less expensive to produce as a design asset. So …

Nunit2.5.10快速上手

1、下載Nunit&#xff1a;http://www.nunit.org/index.php?pdownload&#xff0c;下載MSI格式的安裝包&#xff1b; 2、安裝Nunit&#xff0c;根據提示安裝即可&#xff0c;沒有什么需要配置的&#xff0c;直接下一步就可以了。 3、新建類庫項目NUnitQuickStart&#xff0c;在…

我真的哭了,哭過后呢(-)

這些是山區的孩子們&#xff01; 這是他們的教室。這個也算是&#xff01;如此的師資力量自己解決吃飯問題冬天到了&#xff0c;一起烤烤火與泥土污水一起還好&#xff0c;最大的數字只是10老師抱著孩子來給我們上課了不知道山那邊會是什么呢&#xff1f;又一雙充滿了渴望的大眼…

腦裂問題解決方案_從解決方案到問題

腦裂問題解決方案Once upon a time a couple of years ago, one of my mentors (and favourite people in the world) repeatedly drilled the idea above into my brain. Her advice for Product people was to “fall in love with the problem, not the solution”. At the …