MySQL启动优化

云掣YunChe3周前技术文章52

安装后优化


1.1 数据库启动问题


因为是我们自己配置的参数文件所以启动时需要进行参数文件指定,但是很显然这样会很麻烦,所以我们把它加入到systemctl启动的服务中具体操作如下:


[root@mysql8 ~]# vim /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server 8.0.15
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql_3306/my_3306.cnf  #这里就是我们第一次启动的命令
LimitNOFILE = 5000



保存退出后,测试一下


#启动
[root@mysql8 ~]# systemctl start mysqld
[root@mysql8 ~]# ps -ef | grep mysqld
mysql     29476      1  0 15:53 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql_3306/my_3306.cnf
mysql     31100  29476 10 15:53 ?        00:00:01 /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_3306/my_3306.cnf --basedir=/usr/local/mysql --datadir=/data/mysql/mysql_3306/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/data/mysql/mysql_3306/logs/error.log --open-files-limit=65535 --pid-file=mysql_3306.pid --socket=/data/mysql/mysql_3306/tmp/mysql_3306.sock --port=3306
root      31165  22391  0 15:53 pts/2    00:00:00 grep --color=auto mysqld
#关闭
[root@mysql8 ~]# systemctl stop mysqld
[root@mysql8 ~]# ps -ef | grep mysqld
root      31184  22391  0 15:54 pts/2    00:00:00 grep --color=auto mysqld
#设置开机自启
[root@mysql8 ~]# systemctl enable mysqld



1.2 数据库登陆问题


首先把命令导入到/usr/bin下


[root@mysql8 bin]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@mysql8 ~]# source/etc/profile



上面把启动问题解决但是登陆问题还在,我们用的是自己的配置文件,如果按原来登陆的方式登陆会出现找不到socket文件的错误


ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/data/mysql/mysql_3306/tmp/mysql_3306.sock' (2)


把mysql命令设置别名中指定套接字文件位置


[root@mysql8 ~]# vim .bash_profile
#追加
alias mysql="/usr/local/mysql/bin/mysql  --socket=/data/mysql/mysql_3306/tmp/mysql_3306.sock"
[root@mysql8 ~]# source .bash_profile
[root@mysql8 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.15 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>



1.3 修改密码


mysql> alter user user() identified by '1234';
Query OK, 0 rows affected (0.00 sec)
#登陆测试
[root@mysql8 ~]# mysql -u root -p1234
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.15 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>



配置及优化完成


相关文章

MySQL运维实战(2.4) SSL认证在MySQL中的应用

MySQL支持使用tls进行通信。tls主要有几个作用对客户端、服务端之间的通信数据进行加密。包括客户端发往服务端的SQL,服务端返回给客户端的数据。客户端可以验证服务端的身份。服务端也可以验证客户端...

ACOS统一监控之java应用断诊

ACOS统一监控之java应用断诊

一、前言对于一些使用Java语言搭建的应用架构,java的应用诊断可以帮助开发人员快速发现和解决应用程序中的问题,提高应用程序的性能和稳定性。以下是常用Java应用诊断方法:堆转储分析:使用工具如MA...

Doris 介绍及使用场景

Doris 介绍及使用场景

Doris 介绍                    Apache Doris 是一个基于 MPP 架构的高性能、实时的分析型数据库,以极速易用的特点被人们所熟知,仅需亚秒级响应时间即可返回海量数据...

Nginx实现数据库端口转发

一、需求客户想要将IDC服务器的数据库端口暴漏在公网上,然后其他业务来调数据库接口。为了保证安全,只开放指定的公网ip访问。二、逻辑设计由于客户的IDC服务器与云ECS服务器通过专线打通,所以只需要在...

MySQL优化器特性(八)索引范围扫描成本计算

MySQL优化器特性(八)索引范围扫描成本计算

range执行计划中的range表示索引范围扫描。索引范围扫描的执行过程大致如下:1、根据where条件中索引字段的条件,定位到索引结构中的第一条满足条件的记录。2、根据索引中记录的rowid,到表中...

apiserver指标分析

apiserver指标分析

概述kube-apiserver 是集群所有请求的入口,指标的分析可以反应集群的健康状态。Apiserver 的指标可以分为以下几大类:请求速率和延迟控制器队列的性能etcd 的性能进程状态:文件系统...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。