Linux安装mysql5.6

发布时间 2023-07-17 11:00:36作者: 武魂95级蓝银草

一.下载安装包

选择对应的包 如下5.6包
下载官方 Mysql 包

https://downloads.mysql.com/archives/community/

 二.创建mysql用户组和mysql用户

groupadd mysql && useradd -r -g mysql mysqls

 

上传解压,并初始化

#解压软件包并改名
tar -zxvf mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
mv /usr/local/mysql-5.6.44-linux-glibc2.12-x86_64 /usr/local/mysql
#创建数据目录并赋予权限
mkdir -p /data/mysql
chown mysql:mysql -R /data/mysql
#修改配置文件
cat > /etc/my.cnf << EOF
[mysqld]
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
EOF
#安装初始化依赖
yum -y install autoconf make perl
#执行初始化
cd /usr/local/mysql/scripts/
./mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql

其中: --defaults-file 指定配置文件

–basedir指定Mysql安装目录

–datadir指定数据目录

–user所属用户

四.启动mysql

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

 

五.修改密码

[root@bbb scripts]#  /usr/local/mysql/bin/mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.44 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> update mysql.user set Password=password('mysql') where Host='localhost' and User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

 

六.创建可以远程连接的账号

[root@iZbp1cebowmh8sflwg89tcZ /]# /usr/local/mysql/bin/mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.6.44 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> CREATE USER 'root'@'%' IDENTIFIED BY 'Aa@123456';
ERROR 1396 (HY000): Operation CREATE USER failed for 'root'@'%'
mysql> CREATE USER 'tcc'@'%' IDENTIFIED BY 'Aa@123456';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'tcc'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)