陪你到世界的终结

Accompany you to the end of the world

老婆:老公,你说人为什么要结婚?
老公:我认为是当你老的时候,或是需要被照顾的时候
           那个人可以理直气壮地一直陪在你身边。
老婆:那你会一直陪在我身边吗?
老公:肯定的呀......
  menu
11 文章
0 浏览
3 当前访客
ღゝ◡╹)ノ❤️

Linux下安装MySql5.7

  1. 下载tar包,这里使用wget从官网下载

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

  1. 将mysql安装到/usr/local/mysql下

解压

tar -xvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

移动

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

重命名

mv /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
  1. 新建data目录
mkdir /usr/local/mysql/data
  1. 新建mysql用户、mysql用户组

mysql用户组

groupadd mysql

mysql用户

useradd mysql -g mysql
  1. 将/usr/local/mysql的所有者及所属组改为mysql
chown -R mysql.mysql /usr/local/mysql
  1. 配置
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize

如果出现以下错误:

/usr/local/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

则执行以下命令:

yum -y install numactl

完成后继续安装:

/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize

编辑/etc/my.cnf

[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8

取消密码验证

skip-grant-tables

Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

skip-grant-tables

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
  1. 开启服务

将mysql加入服务

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

开机自启

chkconfig mysql on

开启

service mysql start
  1. 设置密码

登录(由于/etc/my.cnf中设置了取消密码验证,所以此处密码任意)

/usr/local/mysql/bin/mysql -u root -p

操作mysql数据库

use mysql;

修改密码

update user set authentication_string=password('你的密码') where user='root';
flush privileges;
exit;
  1. 将/etc/my.cnf中的skip-grant-tables删除

10、登录再次设置密码(不知道为啥如果不再次设置密码就操作不了数据库了)

/usr/local/mysql/bin/mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY '修改后的密码';
exit;

11、允许远程连接

/usr/local/mysql/bin/mysql -u root -p
use mysql;
GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges;
eixt;

12、添加快捷方式

ln -s /usr/local/mysql/bin/mysql /usr/bin

标题:Linux下安装MySql5.7
作者:JIEHE
地址:http://xn--b2sa.xn--6qq986b3xl/articles/2020/04/08/1586315456883.html