存储架构

Linux安装mysql5.7.20

微信扫一扫,分享到朋友圈

Linux安装mysql5.7.20
0

服务器环境:centos7.1

  1. mysql5.7的tar包百度网盘地址
  2. 操作之如果有默认数据库马瑞DB前先移除mariadb
yum -y remove mari*
rm -rf /var/lib/mysql/*
  1. 使用ftp工具把tar包传输到usr/local/目录下

    image

    推荐工具Xftp 下载地址

  2. 解压tar包

tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
  1. 更改文件名称
mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql
  1. 创建用户和用户组并赋予权限
groupadd mysql
useradd -r -g mysql mysql
chown -R mysql:mysql mysql/
  1. 安装和初始化数据库
cd mysql
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US

如果无错误继续,出现如下错误的

error

报错信息:bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

解决办法:

yum update
yum install -y libaio
  1. 获取初始登录密码 执行上一步操作后会在命令行输出 root@localhost: gFamcspKm2+u localhost: 后面的这一串便是你首次登陆mysql需要的初始密码
    如下图:

    passwd

  2. 配置my.cnf
vim /etc/my.cnf

下面的粘贴进去

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
  1. 启动服务
cd /usr/local/mysql/bin/
./mysqld_safe --user=mysql &
  1. 设置开机启动 进入 /usr/local/mysql文件夹
cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysql
  1. 使用service mysqld命令启动/停止服务
service mysql start/stop/restart

实在不行,用这个:

sudo ./support-files/mysql.server start

注意,5.7版本往上修改密码:

mysql -uroot -p你的密码
use mysql
update mysql.user set authentication_string=password('123456') where user='root'

全局使用mysql

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

新建用户远程连接mysql数据库

grant all on *.* to admin@'%' identified by '123456' with grant option; 
flush privileges;
允许任何ip地址(%表示允许任何ip地址)的电脑用admin帐户和密码(123456)来访问这个mysql server。
注意admin账户不一定要存在。

支持root用户允许远程连接mysql数据库

grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
flush privileges;
  1. 可能出现的错误搜集
  • [x] 解决“ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (111)”
rm -rf /tmp/mysql.sock
cd /usr/local/mysql
sudo ./support-files/mysql.server start
mkdir /var/run/mysqld/
chown -R mysql.mysql /var/run/mysqld/
  • [x] mysql> use mysql

    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

SET PASSWORD = PASSWORD('123456');

Query OK, 0 rows affected, 1 warning (0.00 sec)

  • [x] 启动异常["ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)"]

解决办法:mysql服务未启动,启动就好了.

  • [x] ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
alter user user() identified by "123456";

-[x]服务器重启后连接mysql出现ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/data/mydata/mysql.sock’ (111)类似

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql-5.7.22
datadir=/usr/local/mysql-5.7.22/data
socket=/tmp/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/data/mydata/mysqld.pid
bind-address=0.0.0.0
socket = /data/mydata/mysql.sock
[client]
socket = /data/mydata/mysql.sock

把mysqld.pid的文件换个其他文件夹就行了

阅读原文...


微信扫一扫,分享到朋友圈

Linux安装mysql5.7.20
0

简书

Http 爬虫 socketRead0

上一篇

[iOS 技术文档翻译系列]View Programming Guid for iOS -- Window

下一篇

评论已经被关闭。

插入图片

热门分类

往期推荐

Linux安装mysql5.7.20

长按储存图像,分享给朋友