二进制安装比源码包安装快,方便测试使用啥的。
下载mysql5.6.28二进制包
[root@zxl-nginx src]# wget http://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz
解压mysql5.6.28二进制包
[root@zxl-nginx src]# tar fxz mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz
移动到/usr/local下
[root@zxl-nginx src]# mv mysql-5.6.28-linux-glibc2.5-x86_64 /usr/local/mysql
查看mysql目录下相应的文件及目录
[root@zxl-nginx src]# cd /usr/local/mysql [root@zxl-nginx mysql]# ls bin data include lib mysql-test scripts sql-bench COPYING docs INSTALL-BINARY man README share support-files
创建mysql用户
[root@zxl-nginx local]# useradd mysql -r -s /sbin/nologin -M [root@zxl-nginx local]# id mysql uid=496(mysql) gid=496(mysql) groups=496(mysql)
mysql目录文件更改属主属组为mysql
[root@zxl-nginx local]# chown mysql.mysql mysql/ -R [root@zxl-nginx local]# ll mysql/ -d drwxr-xr-x 13 mysql mysql 4096 Dec 20 05:36 mysql/
初始化mysql的时候提示error无法loading libraries ......
[root@zxl-nginx scripts]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql Installing MySQL system tables.../usr/local/mysql//bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
安装缺少的依赖包文件
[root@zxl-nginx scripts]# yum install libaio libaio-devel -y
再次初始化mysql数据库
[root@zxl-nginx scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
初始化mysql数据库相关信息如下
Installing MySQL system tables...2015-12-20 05:55:00 0 [Warning] TIMESTAMP with implicit .............................. 2015-12-20 05:55:04 6058 [Note] InnoDB: Shutdown completed; log sequence number 1625977 OK .................... ........................ 2015-12-20 05:55:06 6080 [Note] InnoDB: Shutdown completed; log sequence number 1625987 OK support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/local/mysql//bin/mysqladmin -u root password 'new-password' /usr/local/mysql//bin/mysqladmin -u root -h zxl-nginx.com password 'new-password' Alternatively you can run: /usr/local/mysql//bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. ............................ cd . ; /usr/local/mysql//bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at WARNING: Default config file /etc/my.cnf exists on the system This file will be read by default by the MySQL server If you do not want to use this, either remove it, or use the --defaults-file argument to mysqld_safe when starting the server
拷贝my.cnf配置文件到/etc目录下
[root@zxl-nginx mysql]# cp -f my.cnf /etc/my.cnf cp: overwrite `/etc/my.cnf'? y
拷贝mysql服务到相应的目录下
[root@zxl-nginx mysql]# cp support-files/mysql.server /etc/init.d/mysqld [root@zxl-nginx mysql]# ll /etc/init.d/mysqld -rwxr-xr-x 1 root root 10880 Dec 20 05:57 /etc/init.d/mysqld
在mysql my.cnf配置mysql的basedir和datadir目录文件相应的位置,在[mysqld]添加即可,内容如下:
[root@zxl-nginx ~]# cat /etc/my.cnf [mysqld] .................. basedir = /usr/local/mysql datadir = /usr/local/mysql/data
启动mysql服务
[root@zxl-nginx mysql]# /etc/init.d/mysqld restart ERROR! MySQL server PID file could not be found! Starting MySQL. SUCCESS!
查看mysql端口
[root@zxl-nginx mysql]# lsof -i:3306 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 6288 mysql 10u IPv6 33437 0t0 TCP *:mysql (LISTEN)
建议生成环境中mysql安装完成后,一定要运行一次mysql_secure_installation
[root@zxl-nginx bin]# /usr/local/mysql/bin/mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y ... Success! By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] n ... skipping. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL! Cleaning up...
登陆mysql数据库
[root@zxl-nginx bin]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12 Server version: 5.6.28 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 | | test | +--------------------+ 4 rows in set (0.02 sec) mysql> exit Bye [root@zxl-nginx bin]#