MySQL启动优化

云掣YunChe9个月前技术文章1102

安装后优化


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>



配置及优化完成


相关文章

HAProxy

HAProxy

1、HAProxy简介  HAProxy 是一款基于 TCP(第四层)和 HTTP(第七层)应用的代理软件,它也可作为负载均衡器,而且完全免费。 借助 HAProxy,可以快速并且可靠地提供基于 TC...

CDP实操--集群配置Kerberos

CDP实操--集群配置Kerberos

1.1检查IPA设置以及配置Kerberos前提条件登录IPA Server在services页面里都是ipa自带的服务,集群配置完kereros后,这里会增加集群里各项hadoop服务。在host页...

oracle数据库日志清理

1、查看日志执行命令:SQL> show parameter dest;找到audit_file_dest,background_dump_dest,user_dump_dest,core_du...

MySQL 8.0 新特性:Descending Indexes

MySQL 8.0 新特性:Descending Indexes

一、前言MySQL 8.0 之前的索引排序规则之前只允许 ASC 存储,创建时指定 DESC 也会被忽略,8.0 版本为我们带来了 Descending Indexes 降序索引 👏👏👏只能使用 AS...

Kubernetes源码解读(六)-- Informer源码分析

Kubernetes源码解读(六)-- Informer源码分析

Informer 这个词的出镜率很高,我们在很多文章里都可以看到 Informer 的身影,但是我们在源码里真的去找一个叫做 Informer 的对象,却又发现找不到一个单纯的 Informer,但是...

kafka优选副本切换办法

      1. 以topic test为例,假设test的分布为以下状态。Topic:test PartitionCount:3 Replicati...

发表评论    

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