mysql 的安装
安装MYSQL
1. 卸载已有mysql
查看是否已安装mysql:
rpm -qa mysql
有则卸载:
rpm -e --nodeps 文件名称
是否存在与mysql相关的文件或目录:
whereis mysql
是则删除。
查看是否存在mariadb:
rpm -qa | grep mariadb
存在则卸载:
rpm -e --nodeps 文件名 //文件名是上一个命令查询结果
存在/etc/my.cnf,则需要先删除:
rm /etc/my.cnf
2. 安装编译mysql需要的依赖包
yum install libevent* libtool* autoconf* libstd* ncurse* bison* openssl*
3. 安装cmake(mysql5.5之后需要用cmake支持编译安装)
查看是否已安装cmake:
rpm -qa cmake
没有则下载编译安装:
cd /usr/local/src
wget http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz
tar -xf cmake-2.8.12.1.tar.gz
cd cmake-2.8.12.1
./configure
make
make install
检查cmake是否安装成功:
cmake --version
4. 下载mysql包并解压(到/usr/local/src目录)
cd /usr/local/src
wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.38.tar.gz
tar -zxvf mysql-5.6.38.tar.gz
5. 编译安装(到/usr/local/mysql目录)
cd mysql-5.6.38
cmake -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
make(此过程需花费大概20-30分钟)
make install
6. 配置mysql
groupadd mysql
useradd -M -g mysql -s /sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql
7. 初始化配置
cd /usr/local/mysql/scripts
./mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
8. 设置mysql为系统服务
vim /lib/systemd/system/mysql.service
文件内容:
[Unit]
Description=mysql
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
ExecRestart=/usr/local/mysql/support-files/mysql.server restart
ExecReload=/usr/local/mysql/support-files/mysql.server reload
PrivateTmp=true
[Install]
WantedBy=multi-user.target
9. 设置mysql服务开机自启动
systemctl enable mysql.service
10. 启动mysql
systemctl start mysql.service
查看是否启动成功:
ps -A| grep mysql
11. 登录mysql并设置root密码:
/usr/local/mysql/bin/mysql -u root
set password=password('root');