MySQL启动优化

云掣YunChe3个月前技术文章269

安装后优化


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>



配置及优化完成


相关文章

HBase数据结构

1 RowKey与nosql数据库们一样,RowKey是用来检索记录的主键。访问HBASE table中的行,只有三种方式:1.通过单个RowKey访问2.通过RowKey的range(正则)3.全表...

python-序列化和反序列化

1、为什么要序列化内存中的字典、列表、集合以及各种对象,如何保存到一个文件中?如果是自己定义的类的实例,如何保存到一个文件中?如何从文件中读取数据,并让它们在内存中再次恢复成自己对应的类的实例?要设计...

oracle v$archive_log视图过期信息清理

      在使用RMAN命令删除归档后,查询v$archived_log视图会发现name列为空了,但其他列的信息还保留,时间长了会留下很多过期的信息,影响维护工作,需要将过期的信息删除。 出现这样...

数据湖技术之iceberg(七)Spark管理iceberg表

数据湖技术之iceberg(七)Spark管理iceberg表

1.SparkSQL设置catalog配置以下操作主要是SparkSQL操作Iceberg,同样Spark中支持两种Catalog的设置:hive和hadoop,Hive Catalog就是icebe...

keycloak部署和使用

keycloak部署和使用

简介Keycloak是一个开源软件产品,旨在为现代的应用程序和服务,提供包含身份管理和访问管理功能的单点登录工具。截至2018年3月,红帽公司负责管理这一JBoss社区项目,并将其作为他们RH-SSO...

数据库性能大揭秘:玩转MySQL监控指标状态变量

前言在本文中,我们将深入探讨MySQL数据库的性能监控世界。通过了解并应用一系列常用的监控指标,我们能够更精准地把握数据库的运行状况。这些指标,通常以状态变量(status variables)的形式...

发表评论    

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