首页 > 代码库 > CentOS6.5 安装mysql5.6.30
CentOS6.5 安装mysql5.6.30
1、下载解压
由于系统会自带mysql5.1版本的数据库,需要卸载。
[root@localhost src]# yum remove -y mysql-libs
[root@localhost src]# yum remove -y mysql
[root@localhost src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.30.tar.gz
[root@localhost src]# tar -zxvf mysql-5.6.30.tar.gz
[root@localhost src]# mkdir -p /data/mysql 建立数据库存放目录
2、cmake编译过程需要安装包
cmake 编译工具和一些依赖包
[root@localhost src]# cd mysql-5.6.30
[root@localhost mysql-5.6.30]# yum install -y cmake git gcc gcc-c++ ncurses-devel bison
编译过程时间较长(约10分钟)
[root@localhost mysql-5.6.30]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -
DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -
DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -
DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -
DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
[root@localhost mysql-5.6.30]# make
[root@localhost mysql-5.6.30]# make install
3、设置账号、启动mysql
[root@localhost src]# useradd -s /sbin/nologin -M mysql 新建系统用户mysql
[root@localhost src]# chown -R mysql:mysql /data/mysql
[root@localhost src]]# cd /usr/local/mysql/
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql 进行数据库初始化
出现两个ok,初始化正常。
160513 16:59:20 [Note] ./bin/mysqld (mysqld 5.5.48) starting as process 10842 ...
OK
160513 16:59:21 [Note] ./bin/mysqld (mysqld 5.5.48) starting as process 10849 ...
OK
4、拷贝编辑2个文件
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chmod 755 /etc/init.d/mysqld
[root@localhost mysql]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
5、启动服务
[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
[root@localhost mysql]# netstat -lnp | grep mysql
6、登录mysql数据库
初次登录,使用以下命令:
[root@localhost mysql]# /usr/local/mysql/bin/mysql -uroot -p
为了方便期间,修改环境变量,直接使用mysql登录。
[root@localhost mysql]# PATH=$PATH:/usr/local/mysql/bin
[root@localhost mysql]# mysql
[root@localhost mysql]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile 永久添加
7、报错信息。
[root@shell mysql]# service mysqld start
Starting MySQL........ ERROR! The server quit without updating PID file (/var/lib/mysql/shell.pid).
[root@shell mysql]# tail /var/log/mysqld.log
2016-03-02 13:56:17 27366 [Note] InnoDB: Tablespace and datafile system tables created.
2016-03-02 13:56:17 27366 [Note] InnoDB: Waiting for purge to start
2016-03-02 13:56:17 27366 [Note] InnoDB: 5.6.28 started; log sequence number 0
2016-03-02 13:56:17 27366 [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: 7ab85d71-e03b-11e5-83b5-0050569d72a6.
2016-03-02 13:56:17 27366 [Note] Server hostname (bind-address): ‘*‘; port: 3306
2016-03-02 13:56:17 27366 [Note] IPv6 is available.
2016-03-02 13:56:17 27366 [Note] - ‘::‘ resolves to ‘::‘;
2016-03-02 13:56:17 27366 [Note] Server socket created on IP: ‘::‘.
2016-03-02 13:56:17 27366 [ERROR] Fatal error: Can‘t open and lock privilege tables: Table ‘mysql.user‘ doesn‘t exist
160302 13:56:17 mysqld_safe mysqld from pid file /var/lib/mysql/shell.pid ended
解决方法,在/etc/my.cnf添加datadir、basedir路径错误
8、远程登录设置
[root@kelong_1 mysql-5.6.30]# mysqladmin -u root -p password 123456 设置本地登录密码
[root@kelong_1 mysql-5.6.30]# mysql -uroot -p123456
mysql> grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘123456‘;
mysql> flush privileges;
CentOS6.5 安装mysql5.6.30