【MYSQL】MySQL5.6.37二进制安装

时间:2022-10-02 05:59:57

最近有个项目要用到mysql

于是在mysql的论坛中找到了一个5.6.37版本的

下面介绍怎么安装和使用mysql

下载地址:

https://dev.mysql.com/downloads/mysql/5.6.html--这个是官方的,可能已经失效了

下面这个是我上传到云上的

https://pan.baidu.com/s/1raicyKG

【MYSQL】MySQL5.6.37二进制安装

1.下载并上传到服务器中,进行解压,解压到/usr/local下

[root@zhang ~]# tar xvf mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

改下文件名,这个太长了

[root@zhang local ]# mv  mysql-5.6.37-linux-glibc2.12-x86_64 mysql

2.创建mysql的用户和组

创建组:

[root@zhang ~]# groupadd -r -g 306 mysql

创建用户:

[root@zhang ~]# useradd -g 306  -r  -u 306 mysql

3.修改目录的所有者和所属组:

[root@zhang ~]# chown -R mysql.mysql /usr/local/mysql/*

创建存储数据文件的目录(如果有的话就不用创建了)

[root@zhang ~]# mkdir -p /usr/local/mysql/mydata/data

修改所有者和所属组

[root@zhang ~]# chown -R mysql.mysql /usr/local/mysql/mydata

ll mydata

【MYSQL】MySQL5.6.37二进制安装

4.初始化MySQL:

[root@zhang ~]#cd /usr/local/mysql/

[root@zhang mysql]# scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/mydata/data/

5.创建初始化进程,并添加到/etc/init.d/下

[root@zhang mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[root@zhang mysql]# chkconfig --add mysqld

6.配置mysql的配置文件

[root@zhang mysql]# vim /etc/my.cnf 
[mysqld]
datadir=/usr/local/mysql/mydata/data
#socket=/var/lib/mysql/mysql.sock
#user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
basedir=/usr/local/mysql
port=3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 


#[mysqld_safe]
#log-error=/var/log/mysqld.log
#pid-file=/var/run/mysqld/mysqld.pid

7.启动mysql进程

[root@zhang mysql]# service mysqld start

8.查看进程是否启动:

[root@zhang mysql]# lsof -i:3306

COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld  26961 mysql   10u  IPv6  67261      0t0  TCP *:mysql (LISTEN)

9.配置环境变量:

[root@zhang mysql]# cd /root/

[root@zhang ~]# vim .bash_profile

修改下PATH变量

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

export PATH

10.给mysql添加密码

[root@zhang ~]# mysqladmin -u root password 'zhang'

11.登录mysql

[root@zhang ~]# mysql -uroot -p
Enter password: zhang
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.37 MySQL Community Server (GPL)


Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql>

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.02 sec)

基本就可以使用了,这样mysql就彻底配置完成了