码迷,mamicode.com
首页 > 数据库 > 详细

linux 安装MySql 5.7.20

时间:2019-11-29 22:17:42      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:cas   rop   mysqld   files   日志文件   解压   event   访问   show   

1. 下载mysql

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

2. 解压压缩包,并改名为mysql或你自己定义名字


cd /usr/local/

tar -xzvf /data/software/mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz 
mv mysql-5.7.13-linux-glibc2.5-x86_64 mysql

3.创建用户组mysql,创建用户mysql并将其添加到用户组mysql中,并赋予读写权限

groupadd mysql --创建mysql用户组组
useradd -r -g mysql mysql --创建mysql用户并添加到mysql用户组中
chown -R mysql mysql/ --将mysql目录访问权限赋为myql用户
chgrp -R mysql mysql/ --改变mysql目录的用户组属于mysql组

4.创建/编辑配置文件

vim /etc/my.cnf

#复制以下内容

[client]

port = 3306

socket = /tmp/mysql.sock

[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

#不区分大小写

lower_case_table_names = 1

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_pISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

max_connections=5000
 
default-time_zone = ‘+8:00‘

5.初始化数据库

#先安装一下这个,要不然初始化有可能会报错

yum install libaio

#手动编辑一下日志文件,什么也不用写,直接保存退出

cd /var/log/

vim mysqld.log

:wq

chmod 777 mysqld.log

chown mysql:mysql mysqld.log

/usr/local/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

6.查看初始密码

cat /var/log/mysqld.log
最后一行:root@localhost: 这里就是初始密码

7.启动服务,进入mysql,修改初始密码,运行远程连接  


#如果提示必须要修改密码才可以进行操作的话则执行下面操作
set password=password(‘新密码‘);

flush privileges;

UPDATE `mysql`.`user` SET `Host` = ‘%‘,  `User` = ‘root‘  WHERE (`Host` = ‘localhost‘) AND (`User` = ‘root‘);

#然后执行如下操作开启mysql服务,以及设置相关权限
cd /var/run/

mkdir mysqld

chmod 777 mysqld

cd mysqld

vim mysqld.pid

chmod 777 mysqld.pid

chown mysql:mysql mysqld.pid 

/usr/local/mysql/support-files/mysql.server start

/usr/local/mysql/bin/mysql -uroot -p 你在上面看到的初始密码

# 以下是进入数据库之后的sql语句
 use mysql;

 UPDATE `mysql`.`user` SET `Host`=‘%‘, `User`=‘root‘, `Select_priv`=‘Y‘, `Insert_priv`=‘Y‘, `Update_priv`=‘Y‘, `Delete_priv`=‘Y‘, `Create_priv`=‘Y‘, `Drop_priv`=‘Y‘, `Reload_priv`=‘Y‘, `Shutdown_priv`=‘Y‘, `Process_priv`=‘Y‘, `File_priv`=‘Y‘, `Grant_priv`=‘Y‘, `References_priv`=‘Y‘, `Index_priv`=‘Y‘, `Alter_priv`=‘Y‘, `Show_db_priv`=‘Y‘, `Super_priv`=‘Y‘, `Create_tmp_table_priv`=‘Y‘, `Lock_tables_priv`=‘Y‘, `Execute_priv`=‘Y‘, `Repl_slave_priv`=‘Y‘, `Repl_client_priv`=‘Y‘, `Create_view_priv`=‘Y‘, `Show_view_priv`=‘Y‘, `Create_routine_priv`=‘Y‘, `Alter_routine_priv`=‘Y‘, `Create_user_priv`=‘Y‘, `Event_priv`=‘Y‘, `Trigger_priv`=‘Y‘, `Create_tablespace_priv`=‘Y‘, `ssl_type`=‘‘, `ssl_cipher`=‘‘, `x509_issuer`=‘‘, `x509_subject`=‘‘, `max_questions`=‘0‘, `max_updates`=‘0‘, `max_connections`=‘0‘, `max_user_connections`=‘0‘, `plugin`=‘mysql_native_password‘, `authentication_string`=‘*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9‘, `password_expired`=‘N‘, `password_last_changed`=‘2017-11-20 12:41:07‘, `password_lifetime`=NULL, `account_locked`=‘N‘ WHERE  (`User`=‘root‘);

 flush privileges;

8.开机自启

cd /usr/local/mysql/support-files

cp mysql.server /etc/init.d/mysqld

chkconfig --add mysqld

9.使用service mysqld命令启动/停止服务

su - mysql

service mysqld start/stop/restart

10.远程用户建立

grant all privileges on *.* to ‘新用户名‘@‘%‘ identified by ‘新密码‘;

flush privileges;

11. 配置环境变量

vim /etc/profile

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

source /etc/profile

  

然后就妥了

 

 

linux 安装MySql 5.7.20

标签:cas   rop   mysqld   files   日志文件   解压   event   访问   show   

原文地址:https://www.cnblogs.com/YuanWeiBlogger/p/11960527.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!