下載mysql 安裝

http://www.th7.cn/db/mysql/201304/29857.shtml

第一次接觸服務器版Linux,也是第一次用命令行安裝二進制mysql,兩天一晚上,比較痛苦。留作備忘!

首先,下載二進制版本的mysql包: http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz


準備工做:
一、下載mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz
二、將軟件拷貝到目的服務器/work/software目錄下(使用FlashFXPPortable工具,傳輸模式設置爲二進制)
三、在/work/software目錄下輸入如下命令,賦予可執行權限
    chmod 777 mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz


安裝步驟
使用root帳戶登陸服務器
一、解壓tar.gz
tar –xzf mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz

二、重命名解壓的文件夾
mv mysql-5.6.10-linux-glibc2.5-x86_64 mysql

三、將mysql文件夾移動到/usr/local目錄下
sudo mv mysql /usr/local

四、進入mysql目錄
cd /usr/local/mysql

userdel -r mysql
groupdel mysql

五、增長mysql用戶組
sudo groupadd mysql

六、增長mysql用戶
sudo useradd -r -g mysql mysql

七、將mysql文件夾own及grp變動爲mysql
sudo chown -R mysql .
sudo chgrp -R mysql .

八、執行mysql安裝腳本
sudo scripts/mysql_install_db --user=mysql
(若未安裝libaio包,會有一個報錯提示,安裝libaio-dev後,再運行腳本便可)
sudo apt-get install libaio-dev

九、將目錄權限變動回來,僅保留data目錄爲mysql用戶
sudo chown -R root .

sudo chown -R mysql data

十、將mysql配置文件拷貝到etc目錄(全局配置)

注意:5.6版本的默認配置文件名稱由原先的my-medium變動爲了my-default。

sudo cp support-files/my-default.cnf /etc/my.cnf


十一、啓動mysql

sudo bin/mysqld_safe --user=mysql &


十二、初始化mysql root用戶密碼

sudo bin/mysqladmin -u root password '密碼文字'


1三、複製mysql.server腳本到/etc/init.d(初始化服務,有些人喜歡改爲mysqld,在這裏改就能夠)

sudo cp support-files/mysql.server /etc/init.d/mysql.server
sudo cp support-files/mysql.server /etc/init.d/mysqld


1四、查看mysql運行狀態

sudo service mysql.server status
若是運行正常,會顯示 MySQL running。

若是顯示 not running,應該是前面沒有啓動服務,可直接用service mysql.server start啓動

sudo service mysql.server [status|start|stop]


1五、讓mysql開機啓動[defaults],取消開機啓動[remove]

ubuntu  sudo update-rc.d -f mysql.server defaults  [remove]

centos:
        
方法二:在mysql5目錄下找到support-files目錄將其中的mysql.server複製修改成/etc/init.d/mysqld
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld                             
service mysqld start  
chkconfig --level 35 mysqld on

1六、將mysql/bin/mysql命令加入到用戶命令中,或將mysql/bin目錄加入path

加入用戶命令:

sudo ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql

加入環境變量:

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


1七、容許root用戶遠程登陸

    1>進入mysql: mysql –u root –p

    2>改變數據庫: use mysql;

    3>從任意主機登陸: grant all privileges on *.* to root@"%" identified by "密碼文字" with grant option;

    4>從指定主機登陸: grant all privileges on *.* to root@"10.51.14.131" identified by "passw0rd" with grant option;
grant all privileges on *.* to root@"10.51.14.131" identified by "archermind" with grant option;

grant all privileges on *.* to root@"27.17.36.150" identified by "archermind1!2@3#4$" with grant option;

grant all privileges on *.* to root@"211.166.9.218" identified by "archermind1!2@3#4$" with grant option;

 
    grant all privileges on *.* to root@"10.52.12.89" identified by "archermind" with grant option;
    grant all privileges on *.* to root@"10.52.12.36" identified by "archermind" with grant option;

grant all privileges on *.* to root@"10.51.14.31" identified by "archermind" with grant option;
grant all privileges on *.* to root@"10.51.14.42" identified by "archermind" with grant option;
grant all privileges on *.* to root@"10.51.14.131" identified by "archermind" with grant option;


    5>受權生效: flush privileges;

    6>查看host爲%受權是否添加: select * from user;

1八、找個客戶端試試

html

相關文章
相關標籤/搜索