Linux安装MySQL
Linux安装MySQL
1、 MySQL安装包下载
官方下载地址:https://dev.mysql.com/downloads/mysql/5.6.html#downloads
根据Linux版本选择相对应安装包下载
2、 创建安装目录
mkdir /usr/local/mysql
把下载的安装包存放该目录
3、 解压安装包
tar -xvf MySQL-5.6.36-1.el6.x86_64.rpm-bundle.tar
解压文件详情
MySQL-client-5.6.36-1.el6.x86_64.rpm #MySQL客户端程序
MySQL-devel-5.6.36-1.el6.x86_64.rpm #MySQL的库和头文件
MySQL-embedded-5.6.36-1.el6.x86_64.rpm #MySQL的嵌入式程序
MySQL-shared-compat-5.6.36-1.el6.x86_64.rpm #RHEL兼容包
MySQL-shared-5.6.36-1.el6.x86_64.rpm #MySQL的共享库
MySQL-server-5.6.36-1.el6.x86_64.rpm #MySQL服务端程序
MySQL-test-5.6.36-1.el6.x86_64.rpm #MySQL的测试组件
4、 为系统添加mysql组和mysql用户
添加mysql组
groupadd mysql
为mysql组添加mysql用户
useradd -r -g mysql -s /bin/false mysql
注意:Because the user is required only for ownership purposes, not login purposes, the useradd command uses the -r and -s /bin/false options to create a user that does not have login permissions to your server host. Omit these options if your useradd does not support them. (mysql只作为系统账号,不可用于登陆)
5、 mysql目录权限拥有者修改
chown -R mysql:mysql ./
6、 安装准备
查看之前是否有安装
rpm -qa|grep -i mysql
删除安装信息
rpm -e mysql-libs –nodeps
7、 安装MySQL
按照如下顺序进行安装
rpm -ivh MySQL-client-5.6.36-1.el6.x86_64.rpm rpm -ivh MySQL-devel-5.6.36-1.el6.x86_64.rpm rpm -ivh MySQL-server-5.6.36-1.el6.x86_64.rpm rpm -ivh MySQL-shared-5.6.36-1.el6.x86_64.rpm
在安装MySQL-server-5.6.36-1.el6.x86_64.rpm时可能会遇到这种情况,是因为缺少libnuma依赖,需先解决依赖缺少问题再重新安装。
安装依赖方式
(1) yum安装
yum -y install libnuma
(2) 下载缺少的对应包
rpm -ivh numactl-2.0.9-2.el6.x86_64.rpm
8、 安装完成,启动服务
service mysql start
9、 配置MySQL登录密码,并授权主机登陆。
(1) 获取MySQL安装时生成的随机密码
cat /root/.mysql_secret
(2) 通过获取的密码,执行登陆
mysql -uroot –p
(3) 重置root密码
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('p@ssw0rd');
(4) 授权主机登陆
授权任意主机可登录
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'p@ssw0rd' WITH GRANT OPTION;
授权指定主机可登录
GRANT ALL PRIVILEGES ON *.* TO 'root'@'xxx.xxx.xxx.xx' IDENTIFIED BY 'p@ssw0rd' WITH GRANT OPTION;
立即执行新权限
FLUSH PRIVILEGES;
(5) 退出MySQL命令行
quit
10、重启服务
service mysql restart
11、开发3306端口
查看防火墙状态
/etc/init.d/iptables status
查看是否已开发3306端口,没有则开放3306端口
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT