系统环境:
[root@db02 3307]# uname -m x86_64 [root@db02 3307]# uname -r 2.6.32-696.el6.x86_64 [root@db02 3307]# cat /etc/redhat-release CentOS release 6.9 (Final)
安装依赖包:
yum -y install ncurses-devel libaio-devel cmake rpm -qa ncurses-devel libaio-devel cmake
创建mysql管理用户:
useradd -s /sbin/nologin -M mysql id mysql
下载mysql源码包,进行编译安装(耐心等待完成)
将源码包下载到本地/server/tools/目录下
mkdir -p /server/tools mkdir -p /application cd /server/tools/ # 下载源码安装包 wget -q http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36.tar.gz # 下载相应的md5值,进行校验安装包是否完整 # md5sum -c md5sum.log # 一般情况,没什么问题,我就省略了此步骤
解压
tar -zxf mysql-5.6.36.tar.gz cd mysql-5.6.36
编译安装
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.36 \ -DMYSQL_DATADIR=/application/mysql-5.6.36/data \ -DMYSQL_UNIX_ADDR=/application/mysql-5.6.36/tmp/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS=all \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \ -DWITH_ZLIB=bundled \ -DWITH_SSL=bundled \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_EMBEDDED_SERVER=1 \ -DENABLE_DOWNLOADS=1 \ -DWITH_DEBUG=0
检查上一命令是否执行成功
[root@db02 mysql-5.6.36]# echo $? 0
make && make install
创建软链接,方便后期管理
ln -s /application/mysql-5.6.36/ /application/mysql
初始化及配置数据库
# 将参数文件拷贝到/etc/目录下,因为是编译安装,此条命令省略 cp support-files/my*.cnf /etc/my.cnf # 初始化 /application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data --user=mysql # 让mysql用户进行管理,授权 chown -R mysql.mysql /application/mysql/ # mysql的启动文件,拷贝到/etc/init.d/ cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld # 赋予可执行的权限 chmod 700 /etc/init.d/mysqld # 设置开机自启动 chkconfig mysqld on # 查看是否开机自启动设置成功 chkconfig --list mysqld # 启动mysql服务 /etc/init.d/mysqld start # 可能报错(一) Starting MySQL.180402 00:55:13 mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists. ERROR! The server quit without updating PID file (/var/lib/mysql/db02.pid). # 那么你可以查看以下/etc/my.cnf是否是之前安装mysql时产生的文件,把它移动到/tmp目录下,再次启动mysql尝试 /etc/init.d/mysqld start # 可能报错(二) Starting MySQL.Logging to '/application/mysql-5.6.36/data/db02.err'. 180402 00:56:42 mysqld_safe Directory '/application/mysql-5.6.36/tmp' for UNIX socket file don't exists. ERROR! The server quit without updating PID file (/application/mysql-5.6.36/data/db02.pid). # 注:此时数据库启动会提示,找不到xx/tmp/mysql.sock,原因是5.6.36版本不会自动创建tmp目录 # 创建目录tmp mkdir /application/mysql/tmp # 授权 chown -R mysql.mysql /application/mysql/ # 再次启动 /etc/init.d/mysqld start # 启动成功 # 查看服务 netstat -lntup | grep 3306
将mysql的启动目录加入PATH中
echo 'PATH=/application/mysql/bin/:$PATH' >>/etc/profile tail -1 /etc/profile source /etc/profile echo $PATH # 进入mysql数据库,免密登录,无密码 mysql
设置密码:
mysqladmin -u root -p password 'yk123'
修改密码:
mysqladmin -u root -p password '123'
使用用户及密码登陆mysql
mysql -uroot -p123 mysql -uroot -p
基本优化--清理用户及无用数据库
# 进入mysql数据库 mysql -uroot -p123 # 查看mysql数据库的user表的数据 select user,host,password from mysql.user; # 删除无用的数据 drop user 'root'@'db02'; drop user 'root'@'::1'; drop user ''@'localhost'; drop user ''@'db02'; # 查看数据 select user,host,password from mysql.user; # 删除数据库test drop database test; # 查看数据库 show databases;
注:读者应根据自身的情况进行操作,灵活应用!
如有错误,请指正,谢谢!