How to solve Lost connection to MySQL server at 'reading initial communication packet', system error: 0 Question
+0
−0
after
rails db:create
Lost connection to MySQL server at 'reading initial communication packet', syste m error: 0
Couldn't create 'qpixel_dev' database. Please check your configuration.
rails aborted!
Mysql2::Error::ConnectionError: Lost connection to MySQL server at 'reading init ial communication packet', system error: 0
/usr/share/rvm/gems/ruby-2.6.6/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `con nect'
/usr/share/rvm/gems/ruby-2.6.6/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `ini tialize'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/connect ion_adapters/mysql2_adapter.rb:22:in `new'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/connect ion_adapters/mysql2_adapter.rb:22:in `mysql2_connection'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/connect ion_adapters/abstract/connection_pool.rb:830:in `new_connection'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/connect ion_adapters/abstract/connection_pool.rb:874:in `checkout_new_connection'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/connect ion_adapters/abstract/connection_pool.rb:853:in `try_to_checkout_new_connection'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/connect ion_adapters/abstract/connection_pool.rb:814:in `acquire_connection'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/connect ion_adapters/abstract/connection_pool.rb:538:in `checkout'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/connect ion_adapters/abstract/connection_pool.rb:382:in `connection'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/connect ion_adapters/abstract/connection_pool.rb:1033:in `retrieve_connection'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/connect ion_handling.rb:118:in `retrieve_connection'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/connect ion_handling.rb:90:in `connection'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/tasks/m ysql_database_tasks.rb:6:in `connection'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/tasks/m ysql_database_tasks.rb:14:in `create'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/tasks/d atabase_tasks.rb:119:in `create'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/tasks/d atabase_tasks.rb:139:in `block in create_current'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/tasks/d atabase_tasks.rb:316:in `block in each_current_configuration'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/tasks/d atabase_tasks.rb:313:in `each'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/tasks/d atabase_tasks.rb:313:in `each_current_configuration'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/tasks/d atabase_tasks.rb:138:in `create_current'
/usr/share/rvm/gems/ruby-2.6.6/gems/activerecord-5.2.6/lib/active_record/railtie s/databases.rake:29:in `block (2 levels) in <top (required)>'
/usr/share/rvm/gems/ruby-2.6.6/gems/railties-5.2.6/lib/rails/commands/rake/rake_ command.rb:23:in `block in perform'
/usr/share/rvm/gems/ruby-2.6.6/gems/railties-5.2.6/lib/rails/commands/rake/rake_ command.rb:20:in `perform'
/usr/share/rvm/gems/ruby-2.6.6/gems/railties-5.2.6/lib/rails/command.rb:48:in `i nvoke'
/usr/share/rvm/gems/ruby-2.6.6/gems/railties-5.2.6/lib/rails/commands.rb:18:in ` <top (required)>'
/root/qpixel/bin/rails:9:in `require'
/root/qpixel/bin/rails:9:in `<top (required)>'
/usr/share/rvm/gems/ruby-2.6.6/gems/spring-2.1.1/lib/spring/client/rails.rb:28:i n `load'
/usr/share/rvm/gems/ruby-2.6.6/gems/spring-2.1.1/lib/spring/client/rails.rb:28:i n `call'
/usr/share/rvm/gems/ruby-2.6.6/gems/spring-2.1.1/lib/spring/client/command.rb:7: in `call'
/usr/share/rvm/gems/ruby-2.6.6/gems/spring-2.1.1/lib/spring/client.rb:30:in `run '
/usr/share/rvm/gems/ruby-2.6.6/gems/spring-2.1.1/bin/spring:49:in `<top (require d)>'
/usr/share/rvm/gems/ruby-2.6.6/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `lo ad'
/usr/share/rvm/gems/ruby-2.6.6/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `<t op (required)>'
/root/qpixel/bin/spring:13:in `require'
/root/qpixel/bin/spring:13:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
2 answers
+0
−0
+3
−0
You forgot to turn on mysql
.
sudo systemctl enable mysql
systemctl
doesn't work for every distro. If your system doesn't have systemctl
then, you have to use service
sudo service mysql enable
Sometimes only enabling mysql service isn't helpful. Then, you have to login to mysql once.
mysql -u root -p
It will request you to enter password. Then, enter your password. Then, you can exit if you want. Then, try creating database again.
rails db:create
0 comment threads