本篇是在《Linux卸载原生MySQL数据库》的基础之上进行安装,关于安装过程请参考http://www.cnblogs.com/zhuque/archive/2012/11/03/2763353.html 1.环境描述 MySQL版本5.6 OS版本RHEL 6.6 2.安装MySQL前准备 2.1.检查该环境中是否已安装MySQL 1)检查方法:netstat –ano命令查看MySQL默认端口3306是否存在 2)在命令行中执行mysql 3)使用rpm -qa|grep -i mysql查看 2.2.在Oracle Software Delivery Cloud下载MySQL 5.6安装包 安装包V75295-01.zip包含以下rpm包: MySQL-client-advanced-5.6.24-1.el6.x86_64.rpm MySQL-devel-advanced-5.6.24-1.el6.x86_64.rpm MySQL-embedded-advanced-5.6.24-1.el6.x86_64.rpm MySQL-server-advanced-5.6.24-1.el6.x86_64.rpm MySQL-shared-advanced-5.6.24-1.el6.x86_64.rpm MySQL-shared-compat-advanced-5.6.24-1.el6.x86_64.rpm MySQL-test-advanced-5.6.24-1.el6.x86_64.rpm 3.执行安装 通常情况下MySQL安装只需安装MySQL-server和MySQL-client这两个组件包: [root@dbtest5 MySQL]# pwd /root/MySQL [root@dbtest5 MySQL]# yum install MySQL-server-advanced-5.6.24-1.el6.x86_64.rpm Loaded plugins: product-id, refresh-packagekit, security, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Setting up Install Process Examining MySQL-server-advanced-5.6.24-1.el6.x86_64.rpm: MySQL-server-advanced-5.6.24-1.el6.x86_64 Marking MySQL-server-advanced-5.6.24-1.el6.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package MySQL-server-advanced.x86_64 0:5.6.24-1.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================================================================== Package Arch Version Repository Size ==================================================================================================================================================================== Installing: MySQL-server-advanced x86_64 5.6.24-1.el6 /MySQL-server-advanced-5.6.24-1.el6.x86_64 258 M Transaction Summary ==================================================================================================================================================================== Install 1 Package(s) Total size: 258 M Installed size: 258 M Is this ok [y/N]: y Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Warning: RPMDB altered outside of yum. ** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows: 2:postfix-2.6.6-6.el6_5.x86_64 has missing requires of libmysqlclient.so.16()(64bit) 2:postfix-2.6.6-6.el6_5.x86_64 has missing requires of libmysqlclient.so.16(libmysqlclient_16)(64bit) 2:postfix-2.6.6-6.el6_5.x86_64 has missing requires of mysql-libs Installing : MySQL-server-advanced-5.6.24-1.el6.x86_64 1/1 2016-08-12 12:16:53 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2016-08-12 12:16:53 0 [Note] /usr/sbin/mysqld (mysqld 5.6.24-enterprise-commercial-advanced) starting as process 5400 ... 2016-08-12 12:16:53 5400 [Note] InnoDB: Using atomics to ref count buffer pool pages 2016-08-12 12:16:53 5400 [Note] InnoDB: The InnoDB memory heap is disabled 2016-08-12 12:16:53 5400 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2016-08-12 12:16:53 5400 [Note] InnoDB: Memory barrier is not used 2016-08-12 12:16:53 5400 [Note] InnoDB: Compressed tables use zlib 1.2.3 2016-08-12 12:16:53 5400 [Note] InnoDB: Using Linux native AIO 2016-08-12 12:16:53 5400 [Note] InnoDB: Using CPU crc32 instructions 2016-08-12 12:16:53 5400 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2016-08-12 12:16:53 5400 [Note] InnoDB: Completed initialization of buffer pool 2016-08-12 12:16:53 5400 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created! 2016-08-12 12:16:53 5400 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB 2016-08-12 12:16:53 5400 [Note] InnoDB: Database physically writes the file full: wait... 2016-08-12 12:16:53 5400 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB 2016-08-12 12:16:54 5400 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB 2016-08-12 12:16:54 5400 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 2016-08-12 12:16:54 5400 [Warning] InnoDB: New log files created, LSN=45781 2016-08-12 12:16:54 5400 [Note] InnoDB: Doublewrite buffer not found: creating new 2016-08-12 12:16:54 5400 [Note] InnoDB: Doublewrite buffer created 2016-08-12 12:16:54 5400 [Note] InnoDB: 128 rollback segment(s) are active. 2016-08-12 12:16:54 5400 [Warning] InnoDB: Creating foreign key constraint system tables. 2016-08-12 12:16:54 5400 [Note] InnoDB: Foreign key constraint system tables created 2016-08-12 12:16:54 5400 [Note] InnoDB: Creating tablespace and datafile system tables. 2016-08-12 12:16:54 5400 [Note] InnoDB: Tablespace and datafile system tables created. 2016-08-12 12:16:54 5400 [Note] InnoDB: Waiting for purge to start 2016-08-12 12:16:54 5400 [Note] InnoDB: 5.6.24 started; log sequence number 0 2016-08-12 12:16:54 5400 [Note] RSA private key file not found: /var/lib/mysql//private_key.pem. Some authentication plugins will not work. 2016-08-12 12:16:54 5400 [Note] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work. 2016-08-12 12:16:54 5400 [Note] Binlog end 2016-08-12 12:16:54 5400 [Note] InnoDB: FTS optimize thread exiting. 2016-08-12 12:16:54 5400 [Note] InnoDB: Starting shutdown... 2016-08-12 12:16:56 5400 [Note] InnoDB: Shutdown completed; log sequence number 1625977 A random root password has been set. You will find it in '/root/.mysql_secret'. 2016-08-12 12:16:56 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2016-08-12 12:16:56 0 [Note] /usr/sbin/mysqld (mysqld 5.6.24-enterprise-commercial-advanced) starting as process 5423 ... 2016-08-12 12:16:56 5423 [Note] InnoDB: Using atomics to ref count buffer pool pages 2016-08-12 12:16:56 5423 [Note] InnoDB: The InnoDB memory heap is disabled 2016-08-12 12:16:56 5423 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2016-08-12 12:16:56 5423 [Note] InnoDB: Memory barrier is not used 2016-08-12 12:16:56 5423 [Note] InnoDB: Compressed tables use zlib 1.2.3 2016-08-12 12:16:56 5423 [Note] InnoDB: Using Linux native AIO 2016-08-12 12:16:56 5423 [Note] InnoDB: Using CPU crc32 instructions 2016-08-12 12:16:56 5423 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2016-08-12 12:16:56 5423 [Note] InnoDB: Completed initialization of buffer pool 2016-08-12 12:16:56 5423 [Note] InnoDB: Highest supported file format is Barracuda. 2016-08-12 12:16:56 5423 [Note] InnoDB: 128 rollback segment(s) are active. 2016-08-12 12:16:56 5423 [Note] InnoDB: Waiting for purge to start 2016-08-12 12:16:56 5423 [Note] InnoDB: 5.6.24 started; log sequence number 1625977 2016-08-12 12:16:56 5423 [Note] RSA private key file not found: /var/lib/mysql//private_key.pem. Some authentication plugins will not work. 2016-08-12 12:16:56 5423 [Note] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work. 2016-08-12 12:16:56 5423 [Note] Binlog end 2016-08-12 12:16:56 5423 [Note] InnoDB: FTS optimize thread exiting. 2016-08-12 12:16:56 5423 [Note] InnoDB: Starting shutdown... 2016-08-12 12:16:58 5423 [Note] InnoDB: Shutdown completed; log sequence number 1625987 A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER ! You will find that password in '/root/.mysql_secret'. You must change that password on your first connect, no other statement but 'SET PASSWORD' will be accepted. See the manual for the semantics of the 'password expired' flag. Also, the account for the anonymous user has been removed. In addition, you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test database. This is strongly recommended for production servers. See the manual for more instructions. Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com New default config file was created as /usr/my.cnf and will be used by default by the server when you start it. You may edit this file to change server settings Verifying : MySQL-server-advanced-5.6.24-1.el6.x86_64 1/1 Installed: MySQL-server-advanced.x86_64 0:5.6.24-1.el6 Complete! [root@dbtest5 MySQL]# yum install MySQL-client-advanced-5.6.24-1.el6.x86_64.rpm Loaded plugins: product-id, refresh-packagekit, security, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Setting up Install Process Examining MySQL-client-advanced-5.6.24-1.el6.x86_64.rpm: MySQL-client-advanced-5.6.24-1.el6.x86_64 Marking MySQL-client-advanced-5.6.24-1.el6.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package MySQL-client-advanced.x86_64 0:5.6.24-1.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================================================================== Package Arch Version Repository Size ==================================================================================================================================================================== Installing: MySQL-client-advanced x86_64 5.6.24-1.el6 /MySQL-client-advanced-5.6.24-1.el6.x86_64 72 M Transaction Summary ==================================================================================================================================================================== Install 1 Package(s) Total size: 72 M Installed size: 72 M Is this ok [y/N]: y Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : MySQL-client-advanced-5.6.24-1.el6.x86_64 1/1 Verifying : MySQL-client-advanced-5.6.24-1.el6.x86_64 1/1 Installed: MySQL-client-advanced.x86_64 0:5.6.24-1.el6 Complete! 4.检查一下MySQL安装文件及位置 [root@dbtest5 ~]# which mysql /usr/bin/mysql [root@dbtest5 ~]# whereis mysql mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz [root@dbtest5 ~]# find / -name mysql /usr/share/mysql /usr/bin/mysql /usr/lib64/mysql /var/lib/mysql /var/lib/mysql/mysql /etc/rc.d/init.d/mysql /etc/logrotate.d/mysql 1)数据库目录 /var/lib/mysql/ 2)配置文件 /usr/share/mysql(mysql.server命令及配置文件) 3)相关命令 /usr/bin (mysqladmin mysqldump mysql等命令) 4)启动脚本 /etc/rc.d/init.d/(启动脚本文件mysql的目录) 5.启动MySQL [root@dbtest5 ~]# service mysql status MySQL is not running [FAILED] [root@dbtest5 ~]# service mysql start Starting MySQL.. [ OK ] [root@dbtest5 ~]# service mysql status MySQL running (5966) [ OK ] 注意:启动mysql服务也可以使用脚本/etc/init.d/mysql或/usr/share/mysql/mysql.server配置文件来执行,并且MySQL在5.5版本之后服务名从原来的mysqld改为mysql [root@dbtest5 ~]# /etc/init.d/mysql status MySQL running (5966) [ OK ] [root@dbtest5 ~]# /etc/init.d/mysql stop Shutting down MySQL.. [ OK ] [root@dbtest5 ~]# /etc/init.d/mysql start Starting MySQL. [ OK ] [root@dbtest5 ~]# /etc/init.d/mysql status MySQL running (6393) [ OK ] [root@dbtest5 ~]# /usr/share/mysql/mysql.server status MySQL running (6393) [ OK ] [root@dbtest5 ~]# /usr/share/mysql/mysql.server stop Shutting down MySQL.. [ OK ] [root@dbtest5 ~]# /usr/share/mysql/mysql.server start Starting MySQL. [ OK ] [root@dbtest5 ~]# /usr/share/mysql/mysql.server status MySQL running (6601) [ OK ] 6.配置MySQL自启动 [root@dbtest5 ~]# chkconfig --list|grep mysql [root@dbtest5 ~]# chkconfig --add mysql [root@dbtest5 ~]# chkconfig --list|grep mysql mysql 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@dbtest5 ~]# chkconfig --list|grep mysql mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off 7.登陆MySQL 在MySQL 5.5之前版本,安装完成后初始化启动登陆MySQL数据库时,默认不需要使用密码即可登录: [root@dbtest6 ~]# mysql -V mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1 [root@dbtest6 ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, 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 | | test | +--------------------+ 3 rows in set (0.00 sec) 而从MySQL版本从5.5开始,初始化启动登陆MySQL时必须使用密码,否则报下面的错误: [root@dbtest5 ~]# mysql -V mysql Ver 14.14 Distrib 5.6.24, for Linux (x86_64) using EditLine wrapper [root@dbtest5 ~]# mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 这是从安全角度考虑,MySQL在5.5.版本之后安装启动初始化的时候设置了一个随机密码,首次登陆后需要修改,从这段文字提示也可以看出: A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER ! You will find that password in '/root/.mysql_secret'. You must change that password on your first connect, no other statement but 'SET PASSWORD' will be accepted. See the manual for the semantics of the 'password expired' flag. 因此在MySQL安装初始化启动后,首次登陆时需要使用/root/.mysql_secret里随机生成的密码,登陆成功后再进行修改: [root@dbtest5 ~]# cat /root/.mysql_secret # The random password set for the root user at Fri Aug 12 12:16:54 2016 (local time): 1mekXLAbvT20XsvI [root@dbtest5 ~]# mysql -uroot -p1mekXLAbvT20XsvI Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.6.24-enterprise-commercial-advanced 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; ERROR 1820 (HY000): You must SET PASSWORD before executing this statement 这里提示必须先修改密码: mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('oracle'); Query OK, 0 rows affected (0.00 sec) 初始密码修改成功: [root@dbtest5 ~]# mysql -uroot -poracle Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.6.24-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial) 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 | | test | +--------------------+ 4 rows in set (0.00 sec) 8.登陆MySQL报错解决办法 Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ 在登陆MySQL时如果报这个错误,首先检查下MySQL是否启动,其次/var/lib/mysql文件权限是否正确/var/lib/mysql 检查MySQL是否启动:service mysql status 修改MySQL文件权限;chown -R mysql:mysql /var/lib/mysql
Linux安装启动MySQL 5.6
发表回复