CentOS 6.5 MySQL5.6.26源码安装

时间:2021-05-18 14:37:32

一、源码安装cmake工具

从mysql5.5起,mysql源码安装开始使用cmake

wget http://cmake.org/files/v3.2/cmake-3.2.3.tar.gz
tar zxvf cmake-3.2.3.tar.gz
cd cmake-3.2.3
./bootstrap
make
make install
cd ..

二、安装MySQL所需依赖包

yum -y install ncurses-devel libtool openssl-devel

三、安装MySQL

wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.26.tar.gz
useradd -r -s /sbin/nologin mysql
mkdir -pv /usr/local/mysql/data
tar zxvf mysql-5.6.26.tar.gz
cd mysql-5.6.26
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data/ -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DSYSCONFDIR=/etc -DENABLE_DOWNLOADS=1
#出现错误,下次需要:rm -rf CMakeCache.txt
make
make install rm -rf /etc/my.cnf
cp support-files/my-default.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld chown -R mysql.mysql /usr/local/mysql/
##初始化数据库
chmod +x scripts/mysql_install_db
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ ln -s /usr/local/mysql/bin/* /usr/bin/
ln -s /usr/local/mysql/lib/* /usr/lib/
ln -s /usr/local/mysql/man/man1/*  /usr/share/man/man1
ln -s /usr/local/mysql/man/man8/*  /usr/share/man/man8
ln -s /usr/local/mysql/libexec/*  /usr/local/libexec

四、启动mysql服务并加入开机自启动

service mysqld start
chkconfig mysqld on

五、验证mysql服务是否启动

netstat -tulnp | grep
mysql

六、运行MySQL安全设置脚本

修改MySQL用户root的密码,同时可禁止root远程连接,移除test数据库和匿名用户。

mysql_secure_installation

所有选Y即可,也可根据个人爱好

七、MySQL相关
设置mysql登陆密码
例:

mysqladmin -u root password ""