MySQL从5.5版本开始,通过./configure进行编译配置方式已经被取消,取而代之的是cmake工具。 因此,我们首先要在系统中源码编译安装cmake工具。
接下来的安装过程中会遇到错误,我们来一步步探索。
1.安装 cmake
wget http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz
tar zxvf cmake-2.8.12.2.tar.gz
cd cmake-2.8.12.2
./configure
make && make install
2.安装后期用的的依赖:
yum -y install make gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap lsof |
3.检查是否安装mysql 相关软件 在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,否则该文件会干扰源码安装的MySQL的正确配置,造成无法启动。 由于我们已经卸载了最小安装完成后的mysq库所以,就没必要操作了。 centos最小化安装后,会有mysql的库卸载 rpm -qa|grep mysql rpm -e mysql-libs-5.1.73-7.el6.x86_64 --nodeps 4.使用 cmake 编译安装 mysql
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.17.tar.gztar zxvf mysql-5.6.17.tar.gzcd mysql-5.6.17cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_DATADIR=/usr/local/mysql/data \-DSYSCONFDIR=/etc \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_MEMORY_STORAGE_ENGINE=1 \-DWITH_READLINE=1 \-DMYSQL_UNIX_ADDR=/var/lib/mysql/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 \-DMYSQL_USER=mysql \-DWITH_DEBUG=0 \-DWITH_SSL=systemmake && make install 5.修改/usr/local/mysql权限
创建群组groupadd mysql创建一个用户,不允许登陆和不创主目录 useradd -s /sbin/nologin -g mysql -M mysql检查创建用户tail -1 /etc/passwd
chmod +w /usr/local/mysqlchown -R mysql:mysql /usr/local/mysql 6.初始配置: cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf #复制配置文件到etc下 /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql #执行初始化配置脚本,创建系统自带的数据库和表,注意配置文件的路径 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld #复制启动文件到/etc/init.d/下 chmod +x /etc/init.d/mysqld chkconfig mysqld on servier mysqld start vim /etc/profile #在文件末尾添加 设置环境变量 PATH=/usr/local/mysql/bin:$PATH export PATH source /etc/profile #立即生效 7.mysql用户配置: /usr/local/mysql/bin/mysqladmin -uroot -p password '你的密码' 查看用户: select user,host from mysql.user; 删除非必要用户: drop user ""@localhost; drop user root@'::1'; 赋予远程访问权限: GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY 'HU@jiang' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'HU@jiang' WITH GRANT OPTION; GRANT SELECT, INSERT ON test.user TO 'pig'@'%'; grant all privileges on zabbix.* to zabbix@localhost identified by '密码'; flush privileges; 其它一些信息查询: 检查mysql版本 mysql -uroot -p"密码" -e "select version();" 验证mysql安装路径 ls -ld /usr/local/mysql/ 编译安装完成完成基本配置。
附: mysql忘记密码重置方法,同linux ###############以下方法为跳过授权表更改root 密码. [root@localhost ~]# service mysqld stop Shutting down MySQL.. [确定] [root@localhost ~]# service mysqld start --skip-grant-tables Starting MySQL. [确定] [root@localhost ~]# mysql -u root ###免验证登录 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.24 MySQL Community Server (GPL) ................... mysql> update mysql.user set password=password('tarena123') ##新的密码 -> where user='root'and host='localhost'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> quit Bye [root@localhost ~]# service mysqld restart Shutting down MySQL.. [确定] Starting MySQL. [确定] [root@localhost ~]# mysql -u root -p Enter password: tarena123