Ubuntu手動安裝MySQL

從官網下載安裝包http://dev.mysql.com/downloads/mysql/

解壓到/usr/local目錄下,重命名爲mysql

然後在終端輸入以下命令:

shell> groupadd mysql

shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> cd mysql
shell> chown -R mysql .  (別忘了最後有一個點,下同)

shell> chgrp -R mysql .


shell> scripts/mysql_install_db --user=mysql

這句執行後如果報錯:

scripts/mysql_install_db: 244: ./bin/my_print_defaults: not found
Neither host 'ubuntu' nor 'localhost' could be looked up with
./bin/resolveip
Please configure the 'hostname' command to return a correct
hostname.
If you want to solve this at a later stage, restart this script
with the --force option

在終端輸入uname -a命令查看系統版本,如果結果爲x86_64則說明系統是64位的,是不是下載的安裝包不對了?到官網下載64位版本的,把剛解壓到mysql目錄刪掉,重新執行上面這一條語句

如果又報錯:./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

這說明少個東西,執行下面這條命令:

sudo apt-get install libaio-dev

安裝完成後再執行scripts/mysql_install_db --user=mysql這條語句

繼續執行後續命令:

shell> chown -R root .

shell> chown -R mysql data

好了,下面啓動:

sudo ./support-files/mysql.server start


# /usr/local/mysql/bin/mysqld_safe --user=mysql &


cd /usr/local/mysql/bin  //進入 bin目錄

          

    #mysql  //運行mysq命令

 

 如果沒有沒有啓動 或出現 Can't connect to local MySQL server through socket '/tmp/mysql.sock'

 

  解決方法: #cd /usr/local/mysql/support-files //進入該目錄

                  #./mysql.server start  //啓動即可 既可在生成/tmp/mysql.sock
       

  如果/tmp/mysql.sock 無該文件存在,且mysql是處於開啓的狀態?

 

  解決方法: #netstat -an | grep 3306  //查看 3306端口

                       #ps -ef | grep mysql  // 查找 mysql 進程

                       # kill -9  進程號   //強制刪除mysql的進程號

                        #./mysql.server start  //啓動即可 既可在生成/tmp/mysql.sock


            如果在任意路徑下如數mysql命令得到的無該命令咋辦呢?

 

            解決方法:修改 /etc/profile 文件   在文件中加入 

                       PATH=$PATH:/usr/local/mysql/bin/

                       export PATH  (保存即可退出執行 source /etc/profile) 

                    以上操作完既可以 在任意目錄執行# mysql 命令

 

                如果想執行 service mysql start or restart stop 命令咋辦的? 在不能老#./mysql.server start

                    

             解決方法:將 mysql.server  複製一份到 /etc/rc.d/init.d 下並改名 mysql 或 建個連接文件

             假設當前目錄爲 /etc/rc.d/init.d

             如: #cp  /usr/local/mysql/support-files/mysql.server  mysql (複製)

             或 : #ln -s /usr/local/mysql/support-files/mysql.server  mysql (建立連接文件)

             完成以上操作即可  執行 service mysql start (or restart stop)

 

     用如下命令修改MYSQL密碼
# /usr/local/mysql/bin/mysqladmin -u root password yourpassword     //默認安裝密碼爲空,爲了安全你必須馬上修改
# chmod 700 /etc/init.d/mysql
# chkconfig --add mysqld
# chkconfig --level 345 mysql on     //copy編譯目錄的一個腳本設置使mysql每次啓動都能自動運行
 # service mysql start
# netstat -atln
//啓動mysql服務
//查看3306端口是否打開。要注意在防火牆中開放該端口。 

可以用telnet  localhost  3306來測試一下,如果有反映,那就表明安裝成功了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章