转载

MySQL 5.7.9 安装




下载mysql
shell># wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.9.tar.gz
shell># ll
-rw-r--r--  1 root root 312845162 Nov 11 16:25 mysql-5.6.27-linux-glibc2.5-x86_64.tar.gz
-rw-r--r--  1 root root 611640358 Nov 11 16:27 mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz


解压到/usr/local/
shell># tar -zxf mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz -C /usr/local/


检查依赖包libaio,mysql需要使用异步IO
shell># rpm -qa|grep libaio
libaio-0.3.107-10.el6.x86_64


增加mysql组
shell># groupadd mysql
shell># useradd -r -g mysql mysql
设置权限
shell># cd /usr/local
shell># ln -s mysql-5.7.9-linux-glibc2.5-x86_64 mysql
shell># mkdir mysql-files
shell># chmod 770 mysql-files
shell># chown -R mysql .
shell># chgrp -R mysql .


修改相关数据目录
shell># vi /etc/my.cnf 


[mysqld]
datadir=/home/mysql
socket=/home/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0


[mysqld_safe]
log-error=/home/mysql/error.log
pid-file=/home/mysql/mysqld.pid


shell> bin/mysql_install_db --user=mysql    # Before MySQL 5.7.6
shell> bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up
shell> bin/mysql_ssl_rsa_setup              # MySQL 5.7.6 and up


初始化数据库
shell># bin/mysqld --initialize --user=mysql
2015-11-13T03:35:03.910909Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-11-13T03:35:04.051875Z 0 [Warning] InnoDB: New log files created, LSN=45790
2015-11-13T03:35:04.081030Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2015-11-13T03:35:04.134482Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 86fbe8f6-89b7-11e5-aacd-c81f66f10582.
2015-11-13T03:35:04.134868Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2015-11-13T03:35:04.135431Z 1 [Note] A temporary password is generated for root@localhost: nwpD(-Nap1r2
shell># bin/mysql_ssl_rsa_setup
Generating a 2048 bit RSA private key
.....................+++
.....................+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
.................................................................................+++
...........................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
.....................+++
...............................+++
writing new private key to 'client-key.pem'
-----
shell># chown -R root .
shell># ll
total 160
drwxr-xr-x  2 root mysql   4096 Oct 12 15:30 bin
-rw-r--r--  1 root mysql  17987 Oct 12 14:21 COPYING
drwxr-xr-x  2 root mysql   4096 Oct 12 15:30 docs
drwxr-xr-x  3 root mysql   4096 Oct 12 15:30 include
-rw-r--r--  1 root mysql 108028 Oct 12 14:21 INSTALL-BINARY
drwxr-xr-x  5 root mysql   4096 Oct 12 15:30 lib
drwxr-xr-x  4 root mysql   4096 Oct 12 15:29 man
-rw-r--r--  1 root mysql   2478 Oct 12 14:21 README
drwxr-xr-x 28 root mysql   4096 Oct 12 15:30 share
drwxr-xr-x  2 root mysql   4096 Nov 13 11:32 support-files
shell># chown -R mysql /home/mysql


后台启动MySQL
shell># bin/mysqld_safe --user=mysql &
[1] 32559
shell># 151113 11:36:12 mysqld_safe Logging to '/home/mysql/mysqld.log'.
151113 11:36:12 mysqld_safe Starting mysqld daemon with databases from /home/mysql


shell># ps -ef | grep mysql
root     32559 32076  0 11:36 pts/1    00:00:00 /bin/sh bin/mysqld_safe --user=mysql
mysql    32725 32559  0 11:36 pts/1    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/home/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/home/mysql/mysqld.log --pid-file=/home/mysql/mysqld.pid --socket=/home/mysql/mysql.sock
root     32887 32076  0 11:39 pts/1    00:00:00 grep mysql


shell># mysql
-bash: mysql: command not found
增加环境变量
shell># vi .bash_profile 


# .bash_profile


# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi


# User specific environment and startup programs


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


export PATH
~


shell># source .bash_profile 


mysql -uroot -p -S /home/mysql/mysql.sock
Enter password: 


mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.


mysql> ALTER USER 'root'@'localhost' IDENTIFIED by 'oraclemysql';
Query OK, 0 rows affected (0.00 sec)


启动脚本,设置开机自启动
shell># cd /usr/local/mysql
shell># cp support-files/mysql.server /etc/init.d/mysql
shell># /etc/init.d/mysql status
MySQL running (33907)[  OK  ]
shell># chkconfig --list|grep mysql
shell># chkconfig --add mysql
shell># chkconfig --list|grep mysql
mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off


测试安装是否正常
shell># service mysql stop
Shutting down MySQL..[  OK  ]
shell># service mysql start
Starting MySQL.[  OK  ]
shell># mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
shell># mysql -S /home/mysql/mysql.sock -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 2
Server version: 5.7.9 MySQL Community Server (GPL)


Copyright (c) 2000, 2015, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)


正文到此结束
Loading...