作業系統:rhel7.2
MySQL版本:5.7.11
1、MySQL下載下傳
2、上傳MySQL軟體到作業系統
<code>[root@rhel7 ~]</code><code># ls -l mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz </code>
<code>-rw-r--r--. 1 root root 548193637 Dec 4 21:16 mysql-5.7.11-linux-glibc2.5-x86_64.</code><code>tar</code><code>.gz</code>
3、添加mysql使用者群組
<code>[root@rhel7 ~]</code><code># groupadd mysql</code>
<code>[root@rhel7 ~]</code><code># useradd -r -g mysql -s /bin/false mysql</code>
<code>[root@rhel7 ~]</code><code># id mysql</code>
<code>uid=996(mysql) gid=1000(mysql) </code><code>groups</code><code>=1000(mysql)</code>
4、建立目錄、改屬組及解壓檔案
<code>[root@rhel7 ~]</code><code># mkdir -p /opt/mysql/</code>
<code>[root@rhel7 ~]</code><code># mkdir /mysqldata</code>
<code>[root@rhel7 ~]</code><code># mv /root/mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz /opt/mysql/</code>
<code>[root@rhel7 ~]</code><code># cd /opt/mysql/</code>
<code>[root@rhel7 mysql]</code><code># ls</code>
<code>mysql-5.7.11-linux-glibc2.5-x86_64.</code><code>tar</code><code>.gz</code>
<code>[root@rhel7 mysql]</code><code># tar -zxvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz </code>
<code>......</code>
<code>[root@rhel7 mysql]</code><code># mv mysql-5.7.11-linux-glibc2.5-x86_64 mysql5.7.11</code>
<code>[root@rhel7 mysql]</code><code># ls -l</code>
<code>total 535352</code>
<code>drwxr-xr-x. 9 7161 wheel 4096 Feb 2 2016 mysql5.7.11</code>
<code>-rw-r--r--. 1 root root 548193637 Dec 4 21:16 mysql-5.7.11-linux-glibc2.5-x86_64.</code><code>tar</code><code>.gz</code>
<code>[root@rhel7 mysql]</code><code># chown mysql:mysql -R /opt/mysql/</code>
<code>[root@rhel7 mysql]</code><code># chown mysql:mysql -R /mysqldata/</code>
5、初始化庫
<code>[root@rhel7 mysql]</code><code># cd mysql5.7.11/</code>
<code>[root@rhel7 mysql5.7.11]</code><code># ./bin/mysqld --initialize --user=mysql --basedir=/opt/mysql/mysql5.7.11/ --datadir=/mysqldata/</code>
<code>2016-12-04T13:33:01.318081Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation </code><code>for</code> <code>more</code> <code>details).</code>
<code>2016-12-04T13:33:01.729086Z 0 [Warning] InnoDB: New log files created, LSN=45790</code>
<code>2016-12-04T13:33:02.027182Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.</code>
<code>2016-12-04T13:33:02.111882Z 0 [Warning] No existing UUID has been found, so we assume that this is the first </code><code>time</code> <code>that this server has been started. Generating a new UUID: 2dca0cf3-ba26-11e6-b4ff-080027e818bc.</code>
<code>2016-12-04T13:33:02.118970Z 0 [Warning] Gtid table is not ready to be used. Table </code><code>'mysql.gtid_executed'</code> <code>cannot be opened.</code>
<code>2016-12-04T13:33:02.120080Z 1 [Note] A temporary password is generated </code><code>for</code> <code>root@localhost: rqwPw!9iNEEP</code>
<code>[root@rhel7 mysql5.7.11]</code><code># ls /mysqldata/</code>
<code>auto.cnf ib_buffer_pool ibdata1 ib_logfile0 ib_logfile1 mysql performance_schema sys</code>
注意:root的初始密碼已經在日志中給出:rqwPw!9iNEEP
在5.7.6之前的版本中使用bin/mysql_install_db --user=mysql初始化庫。
6、啟動MySQL資料庫
<code>#替換系統自帶的my.cnf檔案</code>
<code>[root@rhel7 mysql5.7.11]</code><code># mv /etc/my.cnf /etc/my.cnf.bak</code>
<code>[root@rhel7 mysql5.7.11]</code><code># cp support-files/my-default.cnf /etc/my.cnf</code>
<code>#在my.cnf中添加如下兩條</code>
<code>[root@rhel7 mysql5.7.11]</code><code># vi /etc/my.cnf</code>
<code>basedir = </code><code>/opt/mysql/mysql5</code><code>.7.11</code>
<code>datadir = </code><code>/mysqldata</code>
<code>#啟動MySQL</code>
<code>[root@rhel7 mysql5.7.11]</code><code># ./bin/mysqld_safe --user=mysql &</code>
<code>[1] 1756</code>
<code>[root@rhel7 mysql5.7.11]</code><code># 2016-12-04T13:44:30.046089Z mysqld_safe Logging to '/mysqldata/rhel7.err'.</code>
<code>2016-12-04T13:44:30.097978Z mysqld_safe Starting mysqld daemon with databases from </code><code>/mysqldata</code>
<code>[root@rhel7 mysql5.7.11]</code><code># ps -ef |grep mysql</code>
<code>root 1756 1182 0 21:44 pts</code><code>/0</code> <code>00:00:00 </code><code>/bin/sh</code> <code>.</code><code>/bin/mysqld_safe</code> <code>--user=mysql</code>
<code>mysql 1876 1756 1 21:44 pts</code><code>/0</code> <code>00:00:00 </code><code>/opt/mysql/mysql5</code><code>.7.11</code><code>/bin/mysqld</code> <code>--basedir=</code><code>/opt/mysql/mysql5</code><code>.7.11 --datadir=</code><code>/mysqldata</code> <code>--plugin-</code><code>dir</code><code>=</code><code>/opt/mysql/mysql5</code><code>.7.11</code><code>/lib/plugin</code> <code>--user=mysql --log-error=</code><code>/m</code>
<code>ysqldata</code><code>/rhel7</code><code>.err --pid-</code><code>file</code><code>=</code><code>/mysqldata/rhel7</code><code>.pidroot 1905 1182 0 21:44 pts</code><code>/0</code> <code>00:00:00 </code><code>grep</code> <code>--color=auto mysql</code>
7、登入MySQL,使用安裝時給出密碼登入并更改root密碼
<code>[root@rhel7 mysql5.7.11]</code><code># ./bin/mysql -uroot -p </code>
<code>Enter password: </code>
<code>Welcome to the MySQL monitor. Commands end with ; or \g.</code>
<code>Your MySQL connection </code><code>id</code> <code>is 2</code>
<code>Server version: 5.7.11</code>
<code>Copyright (c) 2000, 2016, Oracle and</code><code>/or</code> <code>its affiliates. All rights reserved.</code>
<code>Oracle is a registered trademark of Oracle Corporation and</code><code>/or</code> <code>its</code>
<code>affiliates. Other names may be trademarks of their respective</code>
<code>owners.</code>
<code>Type </code><code>'help;'</code> <code>or </code><code>'\h'</code> <code>for</code> <code>help. Type </code><code>'\c'</code> <code>to </code><code>clear</code> <code>the current input statement.</code>
<code>mysql> </code><code>set</code> <code>password=</code><code>'1qaz!QAZ'</code><code>;</code>
<code>Query OK, 0 rows affected (0.01 sec)</code>
注意:5.6之前使用set password=password('newpassword')進行改密碼,5.7版本不再建議這樣改密碼,會有如下提示:
<code>mysql> </code><code>set</code> <code>password=password(</code><code>'123456'</code><code>);</code>
<code>Query OK, 0 rows affected, 1 warning (0.00 sec)</code>
<code>mysql> show warnings;</code>
<code>+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+</code>
<code>| Level | Code | Message |</code>
<code>| Warning | 1287 | </code><code>'SET PASSWORD = PASSWORD('</code><code><plaintext_password></code><code>')'</code> <code>is deprecated and will be removed </code><code>in</code> <code>a future release. Please use SET PASSWORD = </code><code>'<plaintext_password>'</code> <code>instead |</code>
<code>1 row </code><code>in</code> <code>set</code> <code>(0.00 sec)</code>
到此,MySQL5.7.11安裝完成。
配置環境變量就可以友善使用了:
<code>[root@rhel7 mysql5.7.11]</code><code># vi /root/.bash_profile</code>
<code>#添加</code>
<code>export</code> <code>MYSQL_HOME=</code><code>/opt/mysql/mysql5</code><code>.7.11</code>
<code>export</code> <code>PATH=$MYSQL_HOME</code><code>/bin</code><code>:$PATH</code>
<code>[root@rhel7 mysql5.7.11]</code><code># source /root/.bash_profile</code>
關閉MySQL
mysqladmin -uroot -p shutdown
本文轉自hbxztc 51CTO部落格,原文連結:http://blog.51cto.com/hbxztc/1879396,如需轉載請自行聯系原作者