Linux安装mysql-5.7.24

1.在官网上下载好mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

2.通过winscp或者xshell把本地tar包上传到虚拟机上

3.mysql 依赖的库

shell> yum search libaio # search for info 
shell> yum install libaio # install library

4.创建mysql 与用户组,-s /bin/false 表示该用户不能登录

shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql

5.解压安装包至指定目录

tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql

6. mysql 用户添加权限

shell> chown -R mysql ./
shell> chgrp -R mysql ./

7.创建data目录并添加权限(路径可以自己确定)

shell> mkdir -p /data/mysql
shell> chown -R mysql:mysql /data/mysql

8.将mysql/support-files下的mysql.server 复制到 /etc/init.d/下并自定义为mysql

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

9.修改该服务

vim /etc/init.d/mysql

#修改的内容
basedir=/usr/local/mysql
datadir=/data/mysql

10.配置mysql的配置文件

在其他版本的mysql 里面 support-files下有默认的配置文件,而5.7.24这个版本没有,需要自己准备,下面提供一份简单基本配置

在/etc/ 下新建my.cnf ,有些可能会提示已经存在,因为默认装的数据库配置文件也在,直接覆盖就行(centos本身就存在的)

修改为以下的代码就可以了(vim /etc/my.cof)

# *** default location during install, and will be replaced if you
# # *** upgrade to a newer version of MySQL.
 [client]
 port = 3306
 default-character-set=utf8
#
 [mysqld]
 # 一般配置选项
 basedir = /usr/local/mysql
 datadir = /data/mysql
 port = 3306
 character-set-server=utf8
 default_storage_engine = InnoDB
#
 sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#
#

11.初始化数据库进入mysql/bin目录下

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

12.启动mysql服务

service mysql start

13.登录

./mysql -uroot -p

14.修改密码

set password=password('新密码');

15.使用quit退出连接,重新登录

16.添加环境变量

shell> vi /etc/profile

#添加的的变量
PATH=/home/cbt/svr/mysql/bin:$PATH
export PATH 

#让刚才的修改生效
shell> source /etc/profile

17.直接使用mysql命令登录

mysql -uroot -p123456

18.允许远程登陆

mysql> use mysql;
mysql> select host,user from user;
mysql> update user set host='%' where user='root' and host='localhost';
mysql> flush privileges;

19.远程访问测试:

猜你喜欢

转载自blog.csdn.net/qq_40368860/article/details/85219040
今日推荐