mysql 的 rpm/yum 安裝

來源:互聯網
上載者:User

標籤:mysql mysql安裝 mysql找回root密碼




我的安裝環境為 centos6.4       MySQL相關的包由 www.mysql.com

                                                                             dev.mysql.com  下載




用 rpm包的方式安裝 mysql:

[[email protected] ~]# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-5.6.30-1.el6.x86_64.rpm-bundle.tar[[email protected] ~]# lsMySQL-5.6.30-1.el6.x86_64.rpm-bundle.tar[[email protected] ~]# tar xvf MySQL-5.6.30-1.el6.x86_64.rpm-bundle.tar -C /usr/src/mysql/[[email protected] ~]# cd /usr/src/mysql/[[email protected] mysql]# rpm -ivh MySQL-client-5.6.30-1.el6.x86_64.rpm MySQL-devel-5.6.30-1.el6.x86_64.rpm  MySQL-server-5.6.30-1.el6.x86_64.rpm   #  用rpm包要注意依賴關係 報錯基本是軟體包依賴關係的問題    根據報錯資訊 安裝相應的包 解決依賴關係




基於官方 yum源安裝 mysql:

[[email protected] ~]# wget http://dev.mysql.com/get/mysql57-community-release-el6-8.noarch.rpm[[email protected] ~]# lsmysql57-community-release-el6-8.noarch.rpm[[email protected] ~]# rpm -ivh mysql57-community-release-el6-8.noarch.rpm              # 之後自動幫我們配置yum源了[[email protected] ~]# yum install mysql-client mysql-server  # 安裝 mysql


也可以自己搭建MySQL的yum源

如何搭建yum源 見 http://11427860.blog.51cto.com/11417860/1769560


[[email protected] ~]# vim /etc/yum.repos.d/mysql-community.repo   #  裡面有mysql各個版本的源地址 從裡面copy 出來 自己搭建mysql的yum源





啟動 mysql 服務:

[[email protected] ~]# /etc/init.d/mysql start

[[email protected]  ~]# service mysql start



查看 mysql 初始密碼:

[[email protected] ~]# cat /root/.mysql_secret

在MySQL5.6 版本開始 MySQL會產生一個隨機的初始密碼,密碼在  /root/.mysql_secret 中

在MySQL5.6 之前版本 預設都是空密碼的,直接可以登入



[[email protected] ~]# mysql_secure_installation# 之後輸入初始密碼 ...Change the root password? [Y/n]  y  # 輸 y  建立新的 root密碼...Remove anonymous users? [Y/n]  y   # 輸 y  移除匿名使用者# mysql安裝完畢後,預設會安裝一個匿名使用者,這個匿名使用者是用來測試用的,允許任何人從任何地方登入到mysql,但是不能幹其他的事情,這是個安全隱患,刪除它。...Disallow root login remotely? [Y/n]  y  # 是否禁止root使用者從遠處登入到這台機器上,一般在生產環境中 選 y ,提高安全性,如果你要用root使用者登入mysql,往往先使用SSH遠程登入到那台具體的mysql伺服器,再在那台伺服器的本地上使用mysql的root使用者登入。...Remove test database and access to it? [Y/n]  y  # 是否移除 test資料庫  輸 y 移除預設情況下mysql安裝時會建立一個test的庫,這個庫任何人都可以進行訪問,這個庫是用於測試的。...Reload privilege tables now? [Y/n]  y  # 輸 y 讓剛剛對mysql的授權修改立即生效...                        # 之後已近是登入mysql的狀態了


登入mysql

[[email protected] ~]# mysql -uroot -p‘密碼‘mysql>  mysql>SET PASSWRD = PASSWORD(‘newpasswd‘); 設定新密碼



如果找不到初始密碼 或者忘記了root密碼 可以按以下操作來重設root密碼:


修改MySQL的設定檔(預設為/etc/my.cnf)

[[email protected] ~]# vim /etc/my.cnf # 在 [mysqld] 下添加一行 skip-grant-tables


重啟 mysql 服務

[[email protected] ~]# service restart mysql


現在可以不用密碼直接進入mysql

mysql> update mysql.user set authentication_string=password(‘newpassword‘) -> where user=‘root‘ and Host=‘localhost‘;   # 重設root密碼mysql> flush privileges;mysql> quit;


將/etc/my.cnf 還原,重啟mysql服務,用 mysql -uroot -p‘newpassword‘ 登入mysql





用官方rpm包和yum 安裝mysql的特點是簡單速度快,但沒法定製安裝,入門推薦。




本文出自 “11417860” 部落格,請務必保留此出處http://11427860.blog.51cto.com/11417860/1769851

mysql 的 rpm/yum 安裝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.