Linux 操作mysql資料庫 建立庫 匯入、刪除表

來源:互聯網
上載者:User

標籤:start   show   許可權   service   匯入   遠程   行修改   pass   通過   

確保線上的運行資料庫是不可避免的本人小白,因公司上線沒有辦法自己去整伺服器,深刻體會到伺服器大神的霸氣,所以為了增加記憶,服務廣大員友記錄一下

linux mysql 忘記root的密碼無法登陸進mysql

1、修改MySQL的設定檔/etc/my.conf在[mysqld]下面增加一行skip-grant-table;

2、修改設定檔後重啟MySQL service mysqld restart

3、然後使用常規的命令進行登陸mysql mysql -u root -p 在提示輸入密碼的時候直接點擊斷行符號就好

4、登陸進mysql後執行修改密碼的語句 update set password=passeord(‘root‘) where user =‘root‘;這個時候passeord(‘root‘)中root就是最新設定好的root使用者的密碼

5、在執行第一步,將自己添加的skip-grant-table去掉,然後重啟mysql

 

一、Linux MySQL建立 、刪除資料庫

使用命令進入mysql

creat database 資料庫名;

這樣就建立了一個自己明明的資料庫

使用 show databases;可以查看所有的資料庫

二、刪除資料庫

執行命令drop databases 資料庫名;

三、mysql 匯入、匯出資料庫

方法一:

如果沒有資料庫的話則需要先建立資料庫通過 create tables 表名;然後使用show databases;查看資料庫

資料庫如果存在的使用use 資料庫名;這個命令可以進到資料庫內source /root/my.sql;        source /root/my.sql;這個命令是將名為my.sql的資料檔案匯入到資料庫內但是/root/這是Linux上面存放mysql檔案的路徑,根據自己的填寫

方法二:

/usr/local/mysql/bin/mysql -u root -p 資料庫名 < /root/test.sql;

/usr/local/mysql/bin/mysql -u root -p 需要匯入到哪個資料庫的資料庫名 < 需要匯入的資料庫檔案;例如命令:/usr/local/mysql/bin/mysql -u root -p daobidao < /root/test.sql   將資料庫檔案test.sql檔案匯入到daobidao資料庫中; (但需要匯入到哪個資料庫必須要存在)

四、mysql 匯出資料庫的資料和表結構

匯出資料庫的資料和表結構

/usr/local/mysql/bin/mysqldump -u root -p daobidao > /root/dbd.sql Enter password: /usr/local/mysql/bin/mysqldump -u root -p 需要匯出的資料庫 > 匯出存放的資料庫檔案名; 例如命令:/usr/local/mysql/bin/mysqldump -u root -p daobidao > /root/dbd.sql 將daobidao 資料庫匯出,存放在/root/dbd.sql檔案。匯出資料庫的表結構 /usr/local/mysql/bin/mysqldump -u root -p -d daobidao > /root/dbd.sql Enter password: /usr/local/mysql/bin/mysqldump -u root -p -d 需要匯出的資料庫 > 匯出存放的資料庫檔案名; 例如命令:/usr/local/mysql/bin/mysqldump -u root -p -d daobidao > /root/dbd.sql 將daobidao 資料庫匯出表結構,存放在/root/dbd.sql檔案。   通過本地串連遠端資料庫的時候報錯ip:xxx.xxx.xxx.xx禁止串連遠程mysql伺服器 這個原因是因為我門線上mysql的root許可權的問題,我才用的方式是修改root的許可權通過命令進行修改 進入mysql然後再根目錄下面有一個mysql下面有一個user然後進入user執行修改的命令   update user set host=‘%‘ where user = ‘root‘;將root的許可權更改成全部就把問題解決了 

Linux 操作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.