-1

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.

enter image description here

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

enter image description here

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
MElhalees
  • 75
  • 7
  • 1
    I would troubleshoot by enabling the slow query log, and re-run the migrations. This will show me the execution time measured in the MySQL Server. If MySQL recorded the execution time as very quick, then this points to PHP and Laravel code being the culprit. If that's true, then no MySQL configuration will make up for that. – Bill Karwin May 28 '23 at 21:43
  • is it just the migrations that create tables that are the issue? If you have a migration that does nothing or just inserts some rows of data, does that run normally? – apokryfos May 28 '23 at 21:44
  • Is `skip-name-resolve` included? 3 seconds as a time interval seems like a DNS timeout on each connection. – danblack May 28 '23 at 22:57
  • @BillKarwin I tried to do that and there is no any logged info, I set `long_query_time` to 1 sec, and there's no logged info too. I tried to log all queries and the same thing happens :( – MElhalees May 29 '23 at 06:31
  • @apokryfos the migrations files are responsible for creating tables or dropping it, so there's no a rows to insert :( – MElhalees May 29 '23 at 06:33
  • I am asking you to create one for testing purposes to determine if the issue is table creation or running a migration – apokryfos May 29 '23 at 06:35
  • @danblack I tried to this, and the problem still occurs – MElhalees May 29 '23 at 06:37
  • @apokryfos I have updated the question with a screenshot of creating a new table natively. – MElhalees May 29 '23 at 06:48
  • Not sure I understand. Do empty migrations also take 3 seconds to run? Also check where your MySQL data is stored. Make sure it's not on a network drive – apokryfos May 29 '23 at 06:53
  • @apokryfos I updated the question, yes as you said it seems it's a communication problem. – MElhalees May 29 '23 at 07:00
  • @MElhalees - "and the same thing happens" -- Does the slowlog show 3.7sec for `CREATE TABLE`? If so, that points the finger at MySQL, not Laravel. – Rick James May 29 '23 at 14:19
  • @RickJames No, there's no logs for it. I will destroy my laptop, i think this is the best solution. I am kidding, I will try another linux distribution – MElhalees May 29 '23 at 16:51
  • Sound more like abandoning the framework. Many of the questions on this site are about how to work around limitations of the hundred-or-so frameworks. – Rick James May 29 '23 at 16:53
  • @RickJames I have tried fedora, and the same problem happened, it seems there is a problem with my laptop. – MElhalees May 30 '23 at 05:11
  • Just to clarify, are you using Linux installed natively or on WSL2, and is your database also installed natively or is it in a container? – apokryfos May 30 '23 at 06:15
  • @apokryfos I installed it beside win 11 as a dual boot on DELL G5 5590. And the database is installed on the linux distro locally. – MElhalees May 30 '23 at 08:11
  • In laravel try configuring it to connect via a socket rather than tcp/ip by using the `DB_SOCKET` env variable (make it match what's in your mysqld.cnf), or if you are using `localhost` to connect try changing it to `127.0.0.1` (or vice-versa) – apokryfos May 30 '23 at 08:40
  • @apokryfos I install Ubuntu 23.04 again and I have divided the storage (the system on the ssd, and the home on hdd) I installed it carefully this time, and the problem solved!!!!!!!!!! – MElhalees May 30 '23 at 17:23

1 Answers1

-1

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!

MElhalees
  • 75
  • 7