我的博客
欢迎来到我的博客
bunny.icu

CentOS7安装MySQL

CentOS7安装MySQL

删除MySQL相关文件

find / -name mysql|xargs rm -rf

下载

可以在https://downloads.mysql.com/archives/community下载文件,我下载的是mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz

也可以从我的阿里云oss下载

wget https://file-wsg.oss-cn-shanghai.aliyuncs.com/Linux/mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz

解压

tar -zxvf mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz

解压完成后可以移动文件夹:

mv mysql-5.5.62-linux-glibc2.12-x86_64 /usr/local/mysql

添加用户组和用户

先检查是否有mysql用户组和mysql用户

groups mysql

若有,则跳过这一步;若无,则执行:

groupadd mysql
useradd -r -g mysql mysql

进入mysql目录更改权限

cd /usr/local/mysql
chown -R mysql:mysql ./

执行安装脚本

已安装一个依赖,如果已经安装,可以跳过:

yum install -y libaio

执行安装脚本:

./scripts/mysql_install_db --user=mysql

安装完之后修改当前目录拥有者为root用户,修改data目录拥有者为mysql

chown -R root:root ./
chown -R mysql:mysql data

启动mysql

先处理一个权限问题:

mkdir /var/log/mariadb 
touch /var/log/mariadb/mariadb.log 
chown -R mysql:mysql  /var/log/mariadb/

启动:

./support-files/mysql.server start

如果失败,可能需要杀进程:

ps aux|grep mysql|awk '{print$2}'|xargs kill -9

更改mysql密码

./bin/mysqladmin -u root -h localhost.localdomain password '123456'

密码更改后即可登录MySQL:

./bin/mysql -h127.0.0.1 -uroot -p123456

登录之后将其他用户的密码也可改为root:

update mysql.user set password=password('123456') where user='root';
flush privileges;

增加远程登录权限

grant all privileges on *.* to root@'%' identified by '123456';
flush privileges;

执行之后即可远程登录

将MySQL加入Service系统服务

cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
service mysqld restart

配置到环境变量

export PATH=$PATH:/usr/local/mysql/bin

创建软链接

ln /usr/local/mysql/bin/mysql /usr/bin/mysql

启动、停止、重启的命令

service mysqld start
service mysqld stop
service mysqld restart

解决Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’

ln /var/lib/mysql/mysql.sock /tmp/mysql.sock

Reference

Linux下安装MySQL
Linux安装MySQL时候出现log-error set to ‘/var/log/mariadb/mariadb.log’, however file don’t exists.
libaio.so.1: cannot open shared object file解决方法
亲测有效,解决Can ‘t connect to local MySQL server through socket ‘/tmp/mysql.sock ‘(2) “;

版权声明


本作品系原创, 转载须遵循 CC BY-NC-ND 4.0 许可协议
本文标题:CentOS7安装MySQL
本文链接:https://www.bunny.icu/archives/1061

推荐文章

发表评论

textsms
account_circle
email

bunny.icu

CentOS7安装MySQL
CentOS7安装MySQL
扫描二维码继续阅读
2020-03-01