当前位置:网站首页>Linux 配置MySQL
Linux 配置MySQL
2022-08-09 22:01:00 【熙攘。】
1、检查是否安装过sql
[[email protected] ~]# rpm -qa | grep mysql
[[email protected] ~]# rpm -qa | grep mariadb
如果有则卸载:
[[email protected] ~]# sudo yum remove mariadb-libs-5.5.68-1.el7.x86_64
已加载插件:fastestmirror, langpacks
正在解决依赖关系
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.68-1.el7 将被 删除
--> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-9.el7.x86_64 需要
--> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 2:postfix-2.10.1-9.el7.x86_64 需要
--> 正在检查事务
---> 软件包 postfix.x86_64.2.2.10.1-9.el7 将被 删除
--> 解决依赖关系完成依赖关系解决
=======================================================================================
Package 架构 版本 源 大小
=======================================================================================
正在删除:
mariadb-libs x86_64 1:5.5.68-1.el7 @anaconda 4.4 M
为依赖而移除:
postfix x86_64 2:2.10.1-9.el7 @anaconda 12 M事务概要
=======================================================================================
移除 1 软件包 (+1 依赖软件包)安装大小:17 M
是否继续?[y/N]:y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在删除 : 2:postfix-2.10.1-9.el7.x86_64 1/2
正在删除 : 1:mariadb-libs-5.5.68-1.el7.x86_64 2/2
验证中 : 1:mariadb-libs-5.5.68-1.el7.x86_64 1/2
验证中 : 2:postfix-2.10.1-9.el7.x86_64 2/2删除:
mariadb-libs.x86_64 1:5.5.68-1.el7作为依赖被删除:
postfix.x86_64 2:2.10.1-9.el7完毕!
检查是否卸载干净:
[[email protected] ~]# rpm -qa | grep mysql
[[email protected] ~]# rpm -qa | grep mariadb
2、下载并上传MySQL压缩包
官网地址:MySQL :: Download MySQL Community Server
上传至 /usr/local 目录下,解压并重命名:
创建数据库文件存放的文件夹。这个文件夹将来存放每个数据库的库文件 :
[[email protected] local]# cd mysql
[[email protected] mysql]# mkdir mysqldb
3、赋予myql文件权限
执行 chmod -R 777 /usr/local/mysql/ 命令:
[[email protected] ~ ]# chmod -R 777 /usr/local/mysql/
4、创建mysql组和用户
# 创建组
[[email protected] mysql]# groupadd mysql
# 创建用户(-s /bin/false参数指定mysql用户仅拥有所有权,而没有登录权限)
[[email protected] mysql]# useradd -r -g mysql -s /bin/false mysql
# 将用户添加到组中
[[email protected] mysql]# chown -R mysql:mysql ./
5、创建mysql配置文件
[[email protected] ~]# vi usr/local/mysql/etc/my.cnf
添加以下内容:
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/mysqldb
# 允许最大连接数
max_connections=10000
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8
6、安装mysql
进入mysql 安装目录下:
[[email protected] ~]# cd /usr/local/mysql/bin/
安装mysql,并记住初始化随机密码:
[[email protected] bin]# ./mysqld --initialize --console
2022-08-08T17:36:53.599341Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
2022-08-08T17:36:53.599352Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.30) initializing of server in progress as process 5176
2022-08-08T17:36:53.600411Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2022-08-08T17:36:53.605819Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-08-08T17:36:53.849746Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-08-08T17:36:54.639630Z 6 [Note] [MY-010454] [Server] A temporary password is generated for [email protected]: tvrK&0h*Ip<:
7、启动mysql
更改配置文件 my.cnf 权限:
[[email protected] ~]# chmod -R 644 /usr/local/mysql/etc/my.cnf
进入mysql.server服务目录下并启动服务:
[[email protected] ~]# cd /usr/local/mysql/support-files
[[email protected] support-files]# ./mysql.server start
第一次启动会报错:
重新给mysql安装目录赋予一下权限后,再次执行即可:
[[email protected] support-files]# chmod -R 777 /usr/local/mysql
启动成功:
[[email protected] support-files]# ./mysql.server start
my_print_defaults: [Warning] World-writable config file '/usr/local/mysql/etc/my.cnf' is ignored.
Starting MySQL.my_print_defaults: [Warning] World-writable config file '/usr/local/mysql/etc/my.cnf' is ignored.
my_print_defaults: [Warning] World-writable config file '/usr/local/mysql/etc/my.cnf' is ignored.
Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).
[[email protected] support-files]# chmod -R 644 /usr/local/mysql/etc/my.cnf
[[email protected] support-files]# ./mysql.server start
Starting MySQL. SUCCESS![[email protected] support-files]#
8、将mysql添加到系统进程中
[[email protected] bin]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
9、设置mysql自启动
[[email protected] ~]# chmod +x /etc/init.d/mysqld
[[email protected] ~]# systemctl enable mysqld
设置成功。
10、登录mysql
[[email protected] ~]# cd /usr/local/mysql/bin/
[[email protected] bin]# ./mysql -u root -p
输入一开始的随机密码进入mysql:
11、修改root用户登录密码
mysql> alter user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mypassword';
12、设置允许远程登录
mysql> use mysql
mysql> update user set user.Host='%'where user.User='root';
mysql> flush privileges;
mysql> quit
13、重启服务
[[email protected] ~]# systemctl restart mysql
[[email protected] ~]# service mysql restart
查看mysql运行状态:
[[email protected] ~]# systemctl status mysql
14、开放端口3306
15、用navicat测试连接
边栏推荐
猜你喜欢
Under the NVM node installation;The node environment variable configuration
Xiaohei leetcode's refreshing rainy day trip, just finished eating Yufei Beef Noodles, Mala Tang and Beer: 112. Path Sum
电脑系统重装后怎么用打印机扫描出文件?
阿里云架构师金云龙:基于云XR平台的视觉计算应用部署
xctf攻防世界 Web高手进阶区 shrine
AI+Medical: Using Neural Networks for Medical Image Recognition and Analysis
[Cloud Native] 4.2 DevOps Lectures
Activiti7审批流
[Microservice~Nacos] Nacos service provider and service consumer
leetcode 39. 组合总和(完全背包问题)
随机推荐
The kvm virtual machine cannot be started, NOT available, and the PV is larger than the partition
PHP 2D array sorted by a field
Liver all night to write a thirty thousand - word all the commands the SQL database, function, speaks clearly explain operators, content is rich, proposal collection + 3 even high praise!
阿里云架构师金云龙:基于云XR平台的视觉计算应用部署
Js fifteen interview questions (with answers)
leetcode:331. 验证二叉树的前序序列化
R语言ggplot2可视化:使用ggplot2可视化散点图、使用labs参数自定义Y轴的轴标签文本(customize Y axis labels)
Interviewer: How to deal with Redis big key?
Under the NVM node installation;The node environment variable configuration
Leetcode.25 K个一组翻转链表(模拟/递归)
Redis
R语言ggstatsplot包grouped_ggscatterstats函数可视化分组散点图、并添加假设检验结果(包含样本数、统计量、效应大小及其置信区间、显著性、组间两两比较、贝叶斯假设)
mysql 、pg 查询日期处理
JuiceFS 在多云存储架构中的应用 | 深势科技分享
【微服务~Nacos】Nacos服务提供者和服务消费者
阿里云架构师金云龙:基于云XR平台的视觉计算应用部署
JSON 基本使用
第 1 章 一大波数正在靠近——排序
【测试】语句覆盖,判定覆盖,条件覆盖,路径覆盖
2022 首期线下 Workshop!面向应用开发者们的数据应用体验日来了 | TiDB Workshop Day