Mysql基本操作之Mysql密碼重設

來源:互聯網
上載者:User

標籤:小海

☆注釋:Mysql資料庫安裝就不介紹啦 ,原因是每個人安裝路徑不同,所以此步驟忽略,說重點:

1.初始化Mysql資料庫/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --defaults-file=/etc/my.cnf2.將Mysql設定系統啟動cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqldchmod +x /etc/init.d/mysqldchkconfig --add mysqld chkconfig --level 3 mysqld on3.啟動Mysql/etc/init.d/mysqld start

 4.預設登入Mysql是沒有密碼的(mysql -uroot即可登入的),顯然Mysql沒有登入密碼是萬萬不可的,接下來操作:

/usr/local/mysql/bin/mysqladmin -uroot password ‘xiaohai‘然後登入Mysql資料庫/usr/local/mysql/bin/mysql -uroot -pxiaohai   然後就能登入資料庫啦

【問題來了,如果mysql的root密碼忘了怎麼辦?】

其實操作也是很簡單的,首先停掉Mysql資料庫,操作如下:

1./etc/init.d/mysqld stop2.在/etc/my.cnf的[mysqld]的語句中條件一條語句:[mysqld]skip-grant-tables             這樣就可以了,然後儲存退出!3.重啟Mysql   /etc/init.d/mysqld restart  4.重啟後直接連接mysql資料庫/usr/local/mysql/bin/mysql -uroot  就能進入Mysql在資料庫裡面操作:use mysql;update user set password = password(‘[email protected]#xiaohai‘) where user=‘root‘;flush privileges;

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/75/04/wKiom1Ywhl2jQMzNAAEMtCYWHeU477.jpg" title="sql.png" alt="wKiom1Ywhl2jQMzNAAEMtCYWHeU477.jpg" />

5.將剛在/etc/my.cnf檔案中添加額skip-grant-tables去掉,然後重啟Mysql即可登入資料庫,登入密碼是剛重新設定的密碼。


【Mysql之資料庫的匯出】

1.mysql -uroot [email protected]#xiaohai  mysql > /data/mysql.sql將資料庫中的mysql庫匯出到/data/目錄中,並且命名為mysql.sql

【Mysql之資料庫的匯入】

2.mysql -uroot [email protected]#xiaohai mysql < /data/mysql.sql將mysql.sql檔案匯入到資料庫的mysql庫中


本文出自 “小海” 部落格,請務必保留此出處http://hason.blog.51cto.com/8271396/1707332

Mysql基本操作之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.