Linux安裝mysql5.7

來源:互聯網
上載者:User

標籤:HERE   x86_64   移動   switch   pass   files   shel   修改   roo   

  搭建伺服器第一步:安裝資料庫

 我這裡選擇的是比較通用的mysql,滿足大部分的市場需求了。

  首先準備好mysql壓縮包Xshell和Xftp這裡給個地址:https://pan.baidu.com/s/1DHZaroNWV78TYnob5kOTgg

1、在上面的連結下載tar包,或者使用wget從官網下載

  wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

2、將mysql安裝到/usr/local/mysql下

  # 解壓

  tar -xvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

  # 移動

  mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/

  # 重新命名

  mv /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql

3、建立data目錄

  mkdir /usr/local/mysql/data

4、建立mysql使用者、mysql使用者組

  # mysql使用者組

  groupadd mysql

  # mysql使用者

  useradd mysql -g mysql

5、將/usr/local/mysql的所有者及所屬組改為mysql

  chown -R mysql.mysql /usr/local/mysql

6、配置

  /usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data

  # 如果出現以下錯誤:

2018-07-14 06:40:32 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize2018-07-14 06:40:32 [ERROR]   Child process: /usr/local/mysql/bin/mysqldterminated prematurely with errno= 322018-07-14 06:40:32 [ERROR]   Failed to execute /usr/local/mysql/bin/mysqld --bootstrap --datadir=/usr/local/mysql/data --lc-messages-dir=/usr/local/mysql/share --lc-messages=en_US --basedir=/usr/local/mysql-- server log begin ---- server log end --

  # 則使用以下命令:

/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize

  # 如果出現以下錯誤:

/usr/local/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

  # 則執行以下命令:

  yum -y install numactl

  # 完成後繼續安裝:

/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize

  # 編輯/etc/my.cnf

[mysqld]datadir=/usr/local/mysql/databasedir=/usr/local/mysqlsocket=/tmp/mysql.sockuser=mysqlport=3306character-set-server=utf8# 取消密碼驗證skip-grant-tables# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0# skip-grant-tables[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid

  7、開啟服務

  # 將mysql加入服務

  cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

  # 開機自啟

  chkconfig mysql on

  # 開啟

  service mysql start

  8、設定密碼

  # 登入(由於/etc/my.cnf中設定了取消密碼驗證,所以此處密碼任意)

  /usr/local/mysql/bin/mysql -u root -p

  # 操作mysql資料庫

  >>use mysql;

  # 修改密碼

  >>update user set authentication_string=password(‘你的密碼‘) where user=‘root‘;

  >>flush privileges;

  >>exit;

  9、將/etc/my.cnf中的skip-grant-tables刪除

  10、登入再次設定密碼(不知道為啥如果不再次設定密碼就操作不了資料庫了)

  /usr/local/mysql/bin/mysql -u root -p

   >>ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘修改後的密碼‘;

  >>exit;

  11、允許遠端連線

  /usr/local/mysql/bin/mysql -u root -p

  >>use mysql;

  >>update user set host=‘%‘ where user = ‘root‘;

  >>flush privileges;

  >>eixt;

  12、添加捷徑

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

原文引自:https://www.cnblogs.com/daemon-/p/9009360.html

Linux安裝mysql5.7

相關文章

聯繫我們

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