mysql5.7 安装

下载mysql

https://dev.mysql.com/downloads/mysql/5.7.html#downloads

 

 

tar -xvf mysql-5.7.26-linux-glibc2.12-x86_64.tar 

重命名

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

创建用户和用户组

groupadd mysql
useradd -r -g mysql mysql

创建数据目录并赋予权限

mkdir -p  /usr/local/mysql/data              #创建目录
chown mysql:mysql -R /usr/local/mysql/data   #赋予权限

配置my.cnf

vim /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/usr/local/mysql/data/mysql.err
pid-file=/usr/local/mysql/data/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true

初始化数据库

cd /usr/local/mysql/bin/
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql --initialize

 如果报错  

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

缺少依赖 numactl

安装依赖

yum -y install numactl

 

 

启动mysql,修改密码

先将mysql.server放置到/etc/init.d/mysql中

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

修改my.cnf跳过密码验证

[mysqld]
skip-grant-tables

 

启动

service mysql start

登录mysql,直接回车,不需要输入密码

./mysql -u root -p   #bin目录下

重置密码,再修改密码

use mysql;
UPDATE user SET authentication_string=PASSWORD('123456') where USER='root';
 

 然后再修改配置文件,把之前配置跳过 密码删除

vi  my.cnf      删除这一段  (skip-grant-tables)

重启mysql

service mysql restart

第一次登录后会提示重新设置密码

SET PASSWORD = PASSWORD('123456'); 

 

开启任何ip登录

use mysql                                            #访问mysql库
update user set host = '%' where user = 'root';      #使root能再任何host访问
FLUSH PRIVILEGES;                                    #刷新

 

posted @ 2020-04-24 10:54  suruozhong  阅读(138)  评论(0编辑  收藏  举报