当前位置: 首页 > news >正文

linux 安装mysql5.6

  1. 下载mysql安装包
https://dev.mysql.com/downloads/mysql/5.6.html
  1. 卸载系统自带的mariadb
[root@gpap-prod-3 ~]# rpm -qa| grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@gpap-prod-3 ~]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave

删除/etc下的my.cnf文件

[root@gpap-prod-3 ~]# rm -rf /etc/my.cnf.rpmsave 
[root@gpap-prod-3 ~]# rm -rf /etc/my.cnf
  1. 创建mysql用户组,创建mysql用户,并将其加入mysql用户组
[root@gpap-prod-3 ~]# groupadd mysql
[root@gpap-prod-3 ~]# useradd -r -g mysql mysql
  1. 将下载好的二进制包放到/usr/local目录下
mv mysql-5.6.48-linux-glibc2.12-x86_64.tar.gz /usr/local/

解压文件

tar xf mysql-5.6.48-linux-glibc2.12-x86_64.tar.gz

将其命名为mysql

mv mysql-5.6.48-linux-glibc2.12-x86_64 mysql
  1. 在/etc目录下创建新的my.cnf文件
vim my.cnf

my.cnf文件内容如下:

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysqld]
skip-name-resolve
#设置3306端口
port=3306
socket=/var/lib/mysql/mysql.sock
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M

创建my.cnf中涉及到的目录

mkdir /var/lib/mysql
mkdir /var/lib/mysql/mysql
chown -R mysql:mysql /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql/mysql
pwd
/usr/local/mysql
  1. 进入mysql安装目录(/usr/local/mysql)安装autoconf库和libaio库文件
yum -y install autoconf
yum install libaio* -y
  1. 配置mysql
    修改my.cnf文件权限
chmod 777 /etc/my.cnf

设置开机自动启动服务的脚本

cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
./scripts/mysql_install_db --user=mysql

增加mysqld服务控制脚本执行权限

chmod +x /etc/rc.d/init.d/mysqld

将mysql服务加入到系统服务中

chkconfig --add mysqld

检查服务是否生效

chkconfig --list mysqld

输出日志如下:

Note: This output shows SysV services only and does not include nativesystemd services. SysV configuration data might be overridden by nativesystemd configuration.If you want to list systemd services use 'systemctl list-unit-files'.To see services enabled on particular target use'systemctl list-dependencies [target]'.mysqld             0:off    1:off    2:on    3:on    4:on    5:on    6:off

启动mysqld服务

systemctl restart mysqld.service

修改 /etc/profile 文件,将mysql的bin目录加入path环境变量

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

使profile文件的修改生效

source /etc/profile
  1. 如果设置了防火墙,则需要开通3306和8080端口,依次执行以下命令
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --add-port=3306/udp --permanent
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --zone=public --add-port=8080/udp --permanent
firewall-cmd --reload
  1. 创建mysql软连接
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
  1. 修改mysql用户密码
./mysqld_safe --skip-grant-tables

日志输出如下

Warning: World-writable config file '/etc/my.cnf' is ignored
Warning: World-writable config file '/etc/my.cnf' is ignored
210811 14:53:29 mysqld_safe Logging to '/usr/local/mysql/data/gpap-prod-3.err'.
210811 14:53:29 mysqld_safe A mysqld process already exists

启动mysql客户端(密码为空,直接回车即可)

[root@gpap-prod-3 bin]# mysql -uroot -p
Warning: World-writable config file '/etc/my.cnf' is ignored
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.42 MySQL Community Server (GPL)Copyright (c) 2000, 2018, 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>

输入sql,依次查看数据库列表、进入mysql数据库,查看user表相关信息

show databases;
use mysql;
show tables;
desc user;
select USER,HOST,password from user;

查到的用户列表如下所示

+------+-------------+----------+
| USER | HOST        | password |
+------+-------------+----------+
| root | localhost   |          |
| root | gpap-prod-3 |          |
| root | 127.0.0.1   |          |
| root | ::1         |          |
|      | localhost   |          |
|      | gpap-prod-3 |          |
+------+-------------+----------+
6 rows in set (0.00 sec)

将user为root,host为localhost的这条数据进行修改

update user set password=password("你的root账户的密码"), host="%" where user="root" and host="localhost";

再执行刷新sql

flush privileges;
  1. 退出mysqld_safe,杀掉该进程
ps aux | grep mysqld
kill -9 mysqld_safe对应的进程ID
  1. 重启mysqld服务
systemctl restart mysqld.service
  1. 本地使用navicat进行连接测试成功
http://www.lryc.cn/news/523212.html

相关文章:

  • 【Vue3 入门到实战】3. ref 和 reactive区别和适用场景
  • edge浏览器恢复旧版滚动条
  • Flink(十):DataStream API (七) 状态
  • AWTK fscript 中的 输入/出流 扩展函数
  • C# OpenCvSharp 部署3D人脸重建3DDFA-V3
  • 【人工智能】:搭建本地AI服务——Ollama、LobeChat和Go语言的全方位实践指南
  • 数据结构——堆(介绍,堆的基本操作、堆排序)
  • Excel中函数ABS( )的用法
  • 【数据分析】02- A/B 测试:玩转假设检验、t 检验与卡方检验
  • Windows下的C++内存泄漏检测工具Visual Leak Detector (VLD)介绍及使用
  • [苍穹外卖] 1-项目介绍及环境搭建
  • 人物一致性训练测评数据集
  • AI的出现,是否能替代IT从业者?
  • 乘联会:1月汽车零售预计175万辆 环比暴跌33.6%
  • LLM - 大模型 ScallingLaws 的 CLM 和 MLM 中不同系数(PLM) 教程(2)
  • 开发神器之cursor
  • 使用 Ansys Motor-CAD 的自适应模板加速创新
  • RabbitMQ前置概念
  • http转化为https生成自签名证书
  • 《贪心算法:原理剖析与典型例题精解》
  • 【网络协议】【http】【https】RSA+AES-TLS1.2
  • 【数据库】MySQL数据库之约束与多表查询
  • 【Pandas】pandas Series dot
  • 02UML图(D2_行为图)
  • Kali环境变量技巧(The Environment Variable Technique Used by Kali
  • 【C++】如何从源代码编译红色警戒2地图编辑器
  • 安路FPGA开发工具TD:问题解决办法 及 Tips 总结
  • 【Django开发】django美多商城项目完整开发4.0第12篇:商品部分,表结构【附代码文档】
  • IDEA2023版中TODO的使用
  • windows 搭建flutter环境,开发windows程序