Linux下安裝mysql

來源:互聯網
上載者:User

標籤:刪除   .so   ice   開機啟動   options   匿名   mit   glib   color   

linux版本:CentOS7 64位

    1、下載安裝包“mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz

# 安裝依賴yum -y install perl perl-devel autoconf libaio

    2、把下載的安裝包移動到/usr/local/下。

    3、解壓

tar zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz

    4、複製解壓後的mysql目錄到系統的本地軟體目錄

cp mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql -r

    5、添加系統mysql組和mysql使用者

groupadd mysql useradd -r -g mysql -s /bin/false mysql 
注意:Because the user is required only for ownership purposes, not login purposes, the useradd command uses the -r and -s /bin/false options to create a user that does not have login permissions to your server host. Omit these options if your useradd does not support them.

    6、進入安裝mysql軟體目錄,修改目錄擁有者為mysql使用者

cd mysql/ chown -R mysql:mysql ./

    7、安裝資料庫,此處可能出現錯誤。

./scripts/mysql_install_db --user=mysql

    FATAL ERROR: please install the following Perl modules before executing scripts/mysql_install_db:     Data::Dumper

#解決方案: yum install -y perl-Data-Dumper

    8、修改目前的目錄擁有者為root使用者

chown -R root:root ./

    9、修改當前data目錄擁有者為mysql使用者

chown -R mysql:mysql data

============== 到此資料庫安裝完畢 =============

    10、添加mysql服務開機自啟動

添加開機啟動,把啟動指令碼放到開機初始化目錄。

cp support-files/mysql.server /etc/init.d/mysql# 賦予可執行許可權chmod +x /etc/init.d/mysql# 添加服務chkconfig --add mysql # 顯示服務列表chkconfig --list 

如果看到mysql的服務,並且3,4,5都是on的話則成功,如果是off,則執行

chkconfig --level 345 mysql on

    11、啟動mysql服務

#建立缺少的檔案夾 mkdir /var/log/mariadb service mysql start

正常提示資訊:Starting MySQL. SUCCESS!

 

     12、把mysql用戶端放到預設路徑

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

注意:建議使用軟鏈過去,不要直接包檔案複製,便於系統安裝多個版本的mysql

=================== 這是分割線 ==================

通過使用 mysql -uroot -p 串連資料庫(預設資料庫的root使用者沒有密碼,這個需要設定一個密碼)。

錯誤資訊:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)

解決方案:開啟/etc/my.cnf,看看裡面配置的socket位置是什麼目錄。“socket=/var/lib/mysql/mysql.sock”

路徑和“/tmp/mysql.sock”不一致。建立一個軟串連:ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

 到這裡任務算是完成了。之後就可以建立資料庫使用者,然後使用資料庫了。

 

###################### 分割線 ######################

許可權控制

1、去除匿名使用者

# 測試匿名使用者登入mysql -ux3

可以看到匿名使用者可以登入,具有information_schema和test庫的相關許可權。

# 刪除匿名使用者,使用root使用者登入資料庫delete from mysql.user where User=‘‘; flush privileges;

 

再次測試匿名使用者登入

 

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.