英文:
Laravel - artisan migrate takes long time about 3 sec for each table on Ubuntu 22.04 & 23.04
问题
我已安装了最新版本的Ubuntu 23.04,但在使用artisan migrate
命令时出现了问题。问题是每个表的创建过程大约需要3秒钟,如下图所示。
尝试了许多解决方案后,我认为问题的原因是我没有使用LTS版本(22.04)。我尝试在Ubuntu 23.04上安装了(apache2,php8.1,mysql,phpmyadmin),就像我在之前的版本上做的一样。
但问题仍然存在,我尝试增加了MySQL的缓冲池大小,但没有成功。
提前感谢您的帮助。
更新
我尝试使用phpMyAdmin创建表格,如图所示,创建表格需要3.7867秒。
CREATE TABLE `laravel`.`test`(
`id` BIGINT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(200) NOT NULL,
PRIMARY KEY(`id`)
) ENGINE = InnoDB;
更新2
当我尝试在终端中通过MySQL创建表格时,查询时间如下。
mysql> CREATE TABLE `laravel`.`test2` (`id` BIGINT NULL , `name` VARCHAR(200) NOT NULL ) ENGINE = InnoDB;
Query OK, 0 rows affected (0.44 sec)
更新3
这是我的/etc/mysql/mysql.conf.d/mysqld.cnf
文件。
#
# MySQL数据库服务器配置文件。
#
# 可以使用程序支持的所有长选项。
# 运行带有--help的程序以获取可用选项列表,并运行
# --print-defaults以查看实际理解和使用哪些选项。
#
# 有关解释,请参见
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
# 这里是一些特定程序的条目
# 以下值假定您至少有32M RAM
[mysqld]
#
# * 基本设置
#
# user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
datadir = /var/lib/mysql
# 如果MySQL作为复制从机运行,应该更改。参考https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir
tmpdir = /tmp
#
# 默认情况下不是跳过网络,现在的默认情况是只在localhost上监听
# 这更兼容,不会降低安全性。
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
skip-name-resolve
skip-grant-tables
#
# * 微调
#
key_buffer_size = 8G
# max_allowed_packet = 64M
# thread_stack = 256K
# thread_cache_size = -1
# 这替换了启动脚本,并在第一次触摸MyISAM表时检查它们是否需要
myisam-recover-options = BACKUP
# max_connections = 151
# table_open_cache = 4000
#
# * 日志和复制
#
# 这两个位置都会被cronjob轮换。
#
# 记录所有查询
# 请注意,这种日志类型会导致性能下降。
general_log_file = /var/log/mysql/query.log
general_log = 1
#
# 错误日志 - 应该有很少的条目。
#
log_error = /var/log/mysql/error.log
#
# 在这里,您可以看到持续时间特别长的查询
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mysql-slow.log
long_query_time = 2
log-queries-not-using-indexes
#
# 以下内容可用作易于重播的备份日志或用于复制。
# 注意:如果您要设置复制从机,请参阅README.Debian以获取有关
# 需要更改的其他设置。
# server-id = 1
# log_bin = /var/log/mysql/mysql-bin.log
# binlog_expire_logs_seconds = 2592000
max_binlog_size = 100M
# binlog_do_db = include_database_name
# binlog_ignore_db = include_database_name
英文:
I have installed the latest version of ubuntu 23.04, and there was a problem with artisan migrate. The problem is the process takes about 3 sec for each table to be created! as stated in the image below.
After trying many solutions, I thought that the reason is that I am not using the LTS version (22.04). I tried to install it with (apache2, php8.1, mysql, phpmyadmin) as I did on ubuntu 23.04.
And the problem still occurs, I tried to increase the buffer pool size of mysql but it was in vain.
Thanks in advance
UPDATE
I tried to create a table from phpMyAdmin and as shown the creation of the table takes 3.7867 seconds.
CREATE TABLE `laravel`.`test`(
`id` BIGINT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(200) NOT NULL,
PRIMARY KEY(`id`)
) ENGINE = InnoDB;
UPDATE 2
Query time when I tried to create a table via MySQL in the terminal.
mysql> CREATE TABLE `laravel`.`test2` (`id` BIGINT NULL , `name` VARCHAR(200) NOT NULL ) ENGINE = InnoDB;
Query OK, 0 rows affected (0.44 sec)
UPDATE 3
This is my /etc/mysql/mysql.conf.d/mysqld.cnf
file.
#
# The MySQL database server configuration file.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
[mysqld]
#
# * Basic Settings
#
# user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
datadir = /var/lib/mysql
# If MySQL is running as a replication slave, this should be
# changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir
tmpdir = /tmp
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
skip-name-resolve
skip-grant-tables
#
# * Fine Tuning
#
key_buffer_size = 8G
# max_allowed_packet = 64M
# thread_stack = 256K
# thread_cache_size = -1
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options = BACKUP
# max_connections = 151
# table_open_cache = 4000
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
#
# Log all queries
# Be aware that this log type is a performance killer.
general_log_file = /var/log/mysql/query.log
general_log = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mysql-slow.log
long_query_time = 2
log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
# server-id = 1
# log_bin = /var/log/mysql/mysql-bin.log
# binlog_expire_logs_seconds = 2592000
max_binlog_size = 100M
# binlog_do_db = include_database_name
# binlog_ignore_db = include_database_name
答案1
得分: -1
所以,在我尝试了许多解决方案之后,我从头开始重新安装了Ubuntu。但这一次,我将系统文件安装在SSD驱动器上,而将/home安装在HDD驱动器上。
在安装完成后,我为我的NVIDIA GPU安装了一些驱动程序,并进行了所有性能最佳的设置。
我在php.ini中增加了一些配置(这一点我按照这里的教程进行:https://www.cloudbooklet.com/how-to-install-lamp-apache-mysql-php-in-ubuntu-22-04/)。
问题得到了解决!
英文:
So, after a lot of solutions that I have tried. I installed ubuntu from scratch again. But this time rather than installing it on hdd drive, I installed the system files on ssd drive and the /home on the hdd drive.
After the instillation, I installed some drivers for my nvidia GPU, and make the all settings best for performance.
I have increased some configurations in the php.ini. (this point I have followed the tutorial here: https://www.cloudbooklet.com/how-to-install-lamp-apache-mysql-php-in-ubuntu-22-04/)
And the problem was solved!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论