环境准备:
系统:centos 6.10
数据库:mysql-5.6.47
iptables:stop
selinux:disable
ip:(内)172.16.1.40;(外)192.168.1.40
前期准备:
创建软件目录及安装目录:
mkdir -p /server/tools mkdir -p /app/mysql-5.6.47
创建mysql用户:
useradd -s /sbin/nologin -M mysql
安装cmake及依赖包(源为阿里源):
yum -y install cmake yum -y install openssl-devel ncurses-devel
利用tftp将本地软件包上传到/server/tools目录下
编译及安装:
打开/server/tools目录,解压mysql包:
cd /server/tools/ tar xf mysql-5.6.47.tar.gz ls mysql-5.6.47 mysql-5.6.47.tar.gz
进入mysql-5.6.47目录下进行编译:
cd mysql-5.6.47 cmake . -DCMAKE_INSTALL_PREFIX=/app/mysql-5.6.47 -DMYSQL_DATADIR=/app/mysql-5.6.47/data -DMYSQL_UNIX_ADDR=/app/mysql-5.6.47/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all echo $? 0
如果编译出现问题,下次编译前先删除缓存文件;
rm -rf CMakeCache.txt
安装:
make && make install
初始化/优化设置:
设置软连接:
ln -s /app/mysql-5.6.47/ /app/mysql
拷贝配置文件到/etc/下:
cp support-files/my*.cnf /etc/my.cnf
初始化数据库:
/app/mysql/scripts/mysql_install_db --basedir=/app/mysql/ --datadir=/app/mysql/data/ --user=mysql
创建关键目录及设置权限:
mkdir -p /app/mysql/tmp chown -R mysql.mysql /app/mysql
复制启动脚本到/etc/init.d/mysqld:
cp support-files/mysql.server /etc/init.d/mysqld
启动数据库并设置开机启动:(如果出现权限不足给/etc/init.d/mysqld添加权限)
/etc/init.d/mysqld start chkconfig mysqld on
配置mysql环境变量:
echo 'PATH=/app/mysql/bin/:$PATH' >>/etc/profile source /etc/profile echo $PATH /app/mysql/bin/:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
登录验证:
mysql
配置root用户密码:
mysqladmin -uroot -p password 123123 mysql -uroot -p123123 mysql>
删除多余的用户
mysql> select user,host,password from mysql.user; +------+-----------+----------+ | user | host | password | +------+-----------+----------+ | root | localhost | | | root | mysql\_1 | | | root | 127.0.0.1 | | | root | ::1 | | | | localhost | | | | mysql\_1 | | +------+-----------+----------+ 6 rows in set (0.00 sec) mysql> drop user root@'mysql\_1'; mysql> drop user ''@'mysql\_1'; mysql> drop user root@'::1'; mysql> drop user ""@localhost; mysql> drop user root@127.0.0.1; mysql> select user,host,password from mysql.user; +------+-----------+-------------------------------------------+ | user | host | password | +------+-----------+-------------------------------------------+ | root | localhost | *E56A114692FE0DE073F9A1DD68A00EEB9703F3F1 | +------+-----------+-------------------------------------------+ 1 row in set (0.00 sec) quit
安装完成!