Mysql 5.7 Linux安裝詳細步驟

來源:互聯網
上載者:User

標籤:boot   xxxx   my.cnf   copyright   har   local   rest   mysql 5.7   修改   

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

1、下載安裝包
http://dev.mysql.com/downloads/mysql/#downloads
推薦下載通用安裝方法的TAR包(http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar)。
2.檢查庫檔案是否存在,如有刪除。
[[email protected] Desktop]$ rpm -qa | grep mysql
mysql-libs-5.1.52-1.el6_0.1.x86_64[[email protected] ~]# rpm -e mysql-libs-5.1.52.x86_64 --nodeps
[[email protected] ~]#
3.檢查mysql組和使用者是否存在,如無建立。
[[email protected] ~]# cat /etc/group | grep mysql
mysql:x:490:
[[email protected] ~]# cat /etc/passwd | grep mysql
mysql:x:496:490::/home/mysql:/bin/bash
以上為預設存在的情況,如無,執行添加命令:
[[email protected] ~]#groupadd mysql
[[email protected] ~]#useradd -r -g mysql mysql
//useradd -r參數表示mysql使用者是系統使用者,不可用於登入系統。
4.解壓TAR包,更改所屬的組和使用者
[[email protected] ~]# cd /usr/local/
[[email protected] local]# tar xvf mysql-5.7.12-linux-glibc2.5-x86_64.tar
[[email protected] local]# ls -l
total 1306432
-rwxr--r--. 1 root root  668866560 Jun  1 15:07 mysql-5.7.12-linux-glibc2.5-x86_64.tar
-rw-r--r--. 1 7161 wheel 638960236 Mar 28 12:54 mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
-rw-r--r--. 1 7161 wheel  29903372 Mar 28 12:48 mysql-test-5.7.12-linux-glibc2.5-x86_64.tar.gz
[[email protected] local]# tar xvfz mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
[[email protected] local]# mv mysql-5.7.12-linux-glibc2.5-x86_64 mysql
[[email protected] local]# ls -l
total 1306436
drwxr-xr-x. 2 root root       4096 Dec  4  2009 bin
drwxr-xr-x. 2 root root       4096 Dec  4  2009 etc
drwxr-xr-x. 2 root root       4096 Dec  4  2009 games
drwxr-xr-x. 2 root root       4096 Dec  4  2009 include
drwxr-xr-x. 2 root root       4096 Dec  4  2009 lib
drwxr-xr-x. 3 root root       4096 Dec  2 14:36 lib64
drwxr-xr-x. 2 root root       4096 Dec  4  2009 libexec
drwxr-xr-x. 9 7161 wheel      4096 Mar 28 12:51 mysql
-rwxr--r--. 1 root root  668866560 Jun  1 15:07 mysql-5.7.12-linux-glibc2.5-x86_64.tar
-rw-r--r--. 1 7161 wheel 638960236 Mar 28 12:54 mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
-rw-r--r--. 1 7161 wheel  29903372 Mar 28 12:48 mysql-test-5.7.12-linux-glibc2.5-x86_64.tar.gz
drwxr-xr-x. 2 root root       4096 Dec  4  2009 sbin
drwxr-xr-x. 6 root root       4096 Dec  2 14:36 share
drwxr-xr-x. 2 root root       4096 Dec  4  2009 src
[[email protected] local]# chown -R mysql mysql/
[[email protected] local]# chgrp -R mysql mysql/[[email protected] local]# cd mysql/

5.安裝和初始化資料庫
[[email protected] mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2016-06-01 15:23:25 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-06-01 15:23:30 [WARNING] The bootstrap log isn‘t empty:
2016-06-01 15:23:30 [WARNING] 2016-06-01T22:23:25.491840Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2016-06-01T22:23:25.492256Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2016-06-01T22:23:25.492260Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)----------------------
如果改變預設安裝路徑,則需要
1)/etc/my.cnf、/etc/init.d/mysqld中修改
basedir=‘/apps/mysql‘
datadir=‘/apps/mysql/data‘
2)建立ln
mkdir -p /usr/local/mysql/bin
ln -s /apps/mysql/bin/mysqld /usr/local/mysql/bin/mysqld
----------------------

[[email protected] mysql]#
[[email protected] mysql]# cp -a ./support-files/my-default.cnf /etc/my.cnf
[[email protected] mysql]# cp -a ./support-files/mysql.server  /etc/init.d/mysqld
[[email protected] mysql]# cd bin/
[[email protected] bin]# ./mysqld_safe --user=mysql &
[1] 2932
[[email protected] bin]# 2016-06-01T22:27:09.708557Z mysqld_safe Logging to ‘/usr/local/mysql/data/localhost.localdomain.err‘.
2016-06-01T22:27:09.854913Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[[email protected] bin]# /etc/init.d/mysqld restart
Shutting down MySQL..2016-06-01T22:27:50.498694Z mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended
 SUCCESS!
Starting MySQL. SUCCESS!
[1]+  Done                    ./mysqld_safe --user=mysql
[[email protected] bin]#
//設定開機啟動
[[email protected] bin]# chkconfig --level 35 mysqld on
[[email protected] bin]#
6.初始化密碼mysql5.7會產生一個初始化密碼,而在之前的版本首次登陸不需要登入。
[[email protected] bin]# cat /root/.mysql_secret
# Password set for user ‘[email protected]‘ at 2016-06-01 15:23:25
,xxxxxR5H9
[[email protected] bin]# ./mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.12
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql> SET PASSWORD = PASSWORD(‘123456‘);
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

7.添加遠端存取許可權

mysql> use mysql; 
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A


Database changed
mysql> update user set host = ‘%‘ where user = ‘root‘;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0


mysql> select host, user from user;
+-----------+-----------+
| host      | user      |
+-----------+-----------+
| %         | root      |
| localhost | mysql.sys |
+-----------+-----------+
重啟生效
/etc/init.d/mysqld restart
come from:http://blog.csdn.net/wb96a1007/article/details/51559741

Mysql 5.7 Linux安裝詳細步驟

聯繫我們

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