'Unable to set password for the MySQL "root" user' on a Openvz VPS

18,492

Solution 1

Use the command below to change the root password for mysql server

sudo dpkg-reconfigure mysql-server-5.5

Solution 2

I had the exact same issue and it turned out to be a lack of memory issue. Running this script on the host fixed it for me:

#!/bin/bash    
cid=104
vzctl set ${cid} --vmguarpages 1024M --save
vzctl set ${cid} --oomguarpages 1024M --save
vzctl set ${cid} --privvmpages 1024M:1024M --save

Feel free to change 1024 to whatever amount of memory you want your container to have. You will also need to change 104 to the ID of your container.

Share:
18,492

Related videos on Youtube

David
Author by

David

Updated on September 18, 2022

Comments

  • David
    David over 1 year

    I'm trying to install mysql server on my Openvz based VPS running Ubuntu 13.04 64bit and i keep getting this error at the install. I tried multiple times and i also re installed the os with no change at all. If i try to set the root user after i get error 2002 as you can see below..

    I tried to google the problem but i didn't find anything like this, could you please help me?

    Thank in advance

    root@server1:~# apt-get install mysql-server mysql-common mysql-client          Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following extra packages will be installed:
      libdbd-mysql-perl libmysqlclient18 mysql-client-5.5 mysql-server-5.5
    Suggested packages:
      tinyca mailx
    The following NEW packages will be installed:
      libdbd-mysql-perl libmysqlclient18 mysql-client mysql-client-5.5
      mysql-common mysql-server mysql-server-5.5
    0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
    Need to get 0 B/18.0 MB of archives.
    After this operation, 66.9 MB of additional disk space will be used.
    Do you want to continue [Y/n]? y
    Preconfiguring packages ...
     Package configuration
     ──────────────────────────────────────────────────────────────────────────────
    
    
    
    ┌──────────────────────Configuring mysql-server-5.5─────────────────────────┐
    │ While not mandatory, it is highly recommended that you set a password     │
    │ for the MySQL administrative "root" user.                                 │
    │                                                                           │
    │ If this field is left blank, the password will not be changed.            │
    │                                                                           │
    │ New password for the MySQL "root" user:                                   │
    │ ┌───────────────────────────────────────────────────────────────────────┐ │
    │ │                                                                       │ │
    ├─└───────────────────────────────────────────────────────────────────────┘─┤
    │                                 <  OK  >                                  │
    └───────────────────────────────────────────────────────────────────────────┘
    
    
    
    
    
    
    
     Package configuration
     ──────────────────────────────────────────────────────────────────────────────
    
    
    
    
    
                  ┌────────Configuring mysql-server-5.5───────────┐
                  │                                               │
                  │                                               │
                  │ Repeat password for the MySQL "root" user:    │
                  │ ┌───────────────────────────────────────────┐ │
                  │ │                                           │ │
                  ├─└───────────────────────────────────────────┘─┤
                  │                   <  OK  >                    │
                  └───────────────────────────────────────────────┘
    
    
    
    
    
    
    
    Selecting previously unselected package mysql-common.
    (Reading database ... 41054 files and directories currently installed.)
    Unpacking mysql-common (from .../mysql-common_5.5.32-0ubuntu0.13.04.1_all.deb) ...
    Selecting previously unselected package libmysqlclient18:amd64.
    Unpacking libmysqlclient18:amd64 (from .../libmysqlclient18_5.5.32-0ubuntu0.13.04.1_amd64.deb) ...
    Selecting previously unselected package libdbd-mysql-perl.
    Unpacking libdbd-mysql-perl (from .../libdbd-mysql-perl_4.021-1_amd64.deb) ...
    Selecting previously unselected package mysql-client-5.5.
    Unpacking mysql-client-5.5 (from .../mysql-client-5.5_5.5.32-0ubuntu0.13.04.1_amd64.deb) ...
    Processing triggers for man-db ...
    Setting up mysql-common (5.5.32-0ubuntu0.13.04.1) ...
    Selecting previously unselected package mysql-server-5.5.
    (Reading database ... 41140 files and directories currently installed.)
    Unpacking mysql-server-5.5 (from .../mysql-server-5.5_5.5.32-0ubuntu0.13.04.1_amd64.deb) ...
    Selecting previously unselected package mysql-client.
    Unpacking mysql-client (from .../mysql-client_5.5.32-0ubuntu0.13.04.1_all.deb) ...
    Selecting previously unselected package mysql-server.
    Unpacking mysql-server (from .../mysql-server_5.5.32-0ubuntu0.13.04.1_all.deb) ...
    Processing triggers for man-db ...
    Setting up libmysqlclient18:amd64 (5.5.32-0ubuntu0.13.04.1) ...
    Setting up libdbd-mysql-perl (4.021-1) ...
    Setting up mysql-client-5.5 (5.5.32-0ubuntu0.13.04.1) ...
    Setting up mysql-server-5.5 (5.5.32-0ubuntu0.13.04.1) ...
    invoke-rc.d: policy-rc.d denied execution of stop.
     Package configuration
     ──────────────────────────────────────────────────────────────────────────────
    
    ┌───────────────────────Configuring mysql-server-5.5─────────────────────────┐
    │ Unable to set password for the MySQL "root" user                           │
    │                                                                            │
    │ An error occurred while setting the password for the MySQL                 │
    │ administrative user. This may have happened because the account already    │
    │ has a password, or because of a communication problem with the MySQL       │
    │ server.                                                                    │
    │                                                                            │
    │ You should check the account's password after the package installation.    │
    │                                                                            │
    │ Please read the /usr/share/doc/mysql-server-5.5/README.Debian file for     │
    │ more information.                                                          │
    │                                                                            │
    │                                                                            │
    ├────────────────────────────────────────────────────────────────────────────┤
    │                                 <  OK  >                                   │
    └────────────────────────────────────────────────────────────────────────────┘
    
    
    
    invoke-rc.d: policy-rc.d denied execution of start.
    Setting up mysql-client (5.5.32-0ubuntu0.13.04.1) ...
    Setting up mysql-server (5.5.32-0ubuntu0.13.04.1) ...
    Processing triggers for libc-bin ...
    ldconfig deferred processing now taking place
    root@server1:~# sudo mysql_secure_installation
    
    
    
    
    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
          SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
    
    
    In order to log into MySQL to secure it, we'll need the current
    password for the root user.  If you've just installed MySQL, and
    you haven't set the root password yet, the password will be blank,
    so you should just press enter here.
    
    Enter current password for root (enter for none):
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
    Enter current password for root (enter for none):
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
    Enter current password for root (enter for none):
    
    • Cubiq
      Cubiq over 10 years
      please post result of: cat /etc/mysql/my.cnf |grep bind-address and ps aux |grep mysql
    • David
      David over 10 years
      Here you are @Cubiq: root@server1:~# cat /etc/mysql/my.cnf |grep bind-address bind-address = 127.0.0.1 root@server1:~# ps aux |grep mysql root 3971 0.0 0.0 6508 796 pts/1 S+ 13:54 0:00 grep --color=auto mysql
    • Cubiq
      Cubiq over 10 years
      you don't seem to have the mysql service running. can you try service mysql start ?
    • David
      David over 10 years
      It says it's already running...root@server1:~# service mysql status mysql start/post-start, process 21830 post-start process 21831
    • Cubiq
      Cubiq over 10 years
      can you log in with mysql -uroot without password? and with mysql -uroot -p
    • David
      David over 10 years
      Nope ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
    • amnah
      amnah over 10 years
      Not sure if this the same problem, but try this out: askubuntu.com/a/388849/224147
  • David
    David over 10 years
    Restarted mysql service, my.cnf was ok, mysql -u root and similar always gave me ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2), apparmor was previously uninstalled, i reinstalled it and edited the file, restarted apparmor, stopped and started mysql service with sudo mysqld --skip-grant-tables & and i got alway the same error ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) :(
  • Cubiq
    Cubiq over 10 years
    ls -la /var/run/mysqld
  • David
    David over 10 years
    root@server1:~# ls -la /var/run/mysqld total 0 drwxr-xr-x 2 mysql root 40 Aug 28 05:09 . drwxr-xr-x 18 root root 720 Aug 28 05:09 ..
  • Cubiq
    Cubiq over 10 years
    the server doesn't seem to be running
  • David
    David over 10 years
    It always hangs when trying to start but if i press Ctrl+C and try again it says start: Job is already running: mysql
  • Cubiq
    Cubiq over 10 years
    does /usr/bin/mysqld_safe --user=mysql & as root work?
  • David
    David over 10 years
    root@server1:~# /usr/bin/mysqld_safe --user=mysql & [1] 26836 root@server1:~# 130828 05:59:01 mysqld_safe Can't log to error log and syslog at the same time. Remove all --log-error configuration options for --syslog to take effect. 130828 05:59:01 mysqld_safe Logging to '/var/log/mysql/error.log'. 130828 05:59:01 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 130828 05:59:03 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended [1]+ Done /usr/bin/mysqld_safe --user=mysql
  • David
    David over 10 years
    If you see no solution I'm gonna try installing the 12.04 but first if you have other ideas tell me please:)
  • Cubiq
    Cubiq over 10 years
    only thing I can say is give me access to the box (and change password afterwards).
  • Benjamin
    Benjamin about 8 years
    worked for me: the normal setup somehow did not accept my password (maybe to exotic special chars..). with this command i used a different password and it worked!
  • Shautieh
    Shautieh over 7 years
    Didn't work for me: same error as before.