Laravel - 在Ubuntu 22.04和23.04上,每个表的手工迁移需要很长时间,大约3秒

Laravel - artisan migrate takes long time about 3 sec for each table on Ubuntu 22.04 & 23.04

提问人:MElhalees 提问时间:5/29/2023 最后编辑:MElhalees 更新时间:5/31/2023 访问量:151

问:

我已经安装了最新版本的 ubuntu 23.04,但 artisan migrate 存在问题。问题是创建每个表的过程大约需要 3 秒!如下图所示。

enter image description here

在尝试了许多解决方案之后,我认为原因是我没有使用 LTS 版本 (22.04)。我尝试像在 ubuntu 23.04 上一样使用(apache2、php8.1、mysql、phpmyadmin)安装它。

并且问题仍然存在,我试图增加mysql的缓冲池大小,但徒劳无功。

提前致谢

更新

enter image description here

我尝试从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

#
# 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
mysql laravel apache ubuntu laravel-migrations

评论

1赞 Bill Karwin 5/29/2023
我会通过启用慢速查询日志来排除故障,然后重新运行迁移。这将显示在MySQL服务器中测量的执行时间。如果MySQL记录的执行时间非常快,那么这表明PHP和Laravel代码是罪魁祸首。如果这是真的,那么没有MySQL配置可以弥补这一点。
0赞 apokryfos 5/29/2023
问题是否只是创建表的迁移?如果您的迁移不执行任何操作或仅插入一些数据行,则该迁移是否正常运行?
0赞 danblack 5/29/2023
是否包括在内?3 秒作为时间间隔似乎是每个连接的 DNS 超时。skip-name-resolve
0赞 MElhalees 5/29/2023
@BillKarwin我尝试这样做并且没有任何记录的信息,我设置为 1 秒,也没有记录的信息。我试图记录所有查询,但同样的事情发生在:(long_query_time
0赞 MElhalees 5/29/2023
@apokryfos迁移文件负责创建表或删除表,因此没有要插入的行:(

答:

-1赞 MElhalees 5/31/2023 #1

所以,在我尝试了很多解决方案之后。我再次从头开始安装了ubuntu。但这次我没有将其安装在硬盘驱动器上,而是将系统文件安装在 ssd 驱动器上,将 /home 安装在硬盘驱动器上。

灌输后,我为我的 nvidia GPU 安装了一些驱动程序,并使所有设置都达到最佳性能。

我在php.ini中增加了一些配置。(这一点我已经按照这里的教程进行了操作:https://www.cloudbooklet.com/how-to-install-lamp-apache-mysql-php-in-ubuntu-22-04/)

问题解决了!