简体   繁体   中英

Problems installing mysql in ubuntu 18.04

I have installed mysql since upgrading the operating system. But there seems to be a problem with the root password. I have tried to fix this in many ways on the web, so far it has not been successful.

systemctl status mysql.service give:

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2018-05-02 16:57:24 +07; 13s ago
  Process: 6172 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=217/USER)
Thg 5 02 16:57:24 thiennguyen systemd[1]: mysql.service: Service hold-off time  over, scheduling restart.
Thg 5 02 16:57:24 thiennguyen systemd[1]: mysql.service: Scheduled restart job,  restart counter is at 5.
Thg 5 02 16:57:24 thiennguyen systemd[1]: Stopped MySQL Community Server.
Thg 5 02 16:57:24 thiennguyen systemd[1]: mysql.service: Start request repeated too quickly
Thg 5 02 16:57:24 thiennguyen systemd[1]: mysql.service: Failed with result 'exit-code'.
Thg 5 02 16:57:24 thiennguyen systemd[1]: Failed to start MySQL Community Server

journalctl -xe give: http://codepad.org/6EbGVu2Q

mysql_secure_installation give:

Securing the MySQL server deployment.
Enter password for user root: 
Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

mysql -u root -p give:

Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Especially when I install, mysql does not require setting password for root and i have reinstalled many times. Maybe the problem is old, but I have found many ways on the network but can not solve, so look forward to the help.

The answer marked as correct is technically not right. Ubuntu 18.04 uses sockets for authorization and not passwords!!

( https://websiteforstudents.com/mariadb-installed-without-password-prompts-for-root-on-ubuntu-17-10-18-04-beta/ )

For me logging in was as simple as:

sudo  mysql -u root      

I feel whoever is responsible for this "feature" really dropped the ball. There should have been a message stating that Ubuntu no longer used passwords when attempting to run mysql. this was a really drastic change in functionality.

You have to change the old password of MySQL at the time of secure installation. If you don't remember the old password try following way via root privilege:-

Stop the MySQL service.

service mysql stop

Start MySQL without password and permission checks.

mysqld_safe --skip-grant-tables &

Connect to MySQL

mysql -u root mysql

Run following commands to set a new password for root user.

UPDATE user SET password=PASSWORD('NEW_PASSWORD') WHERE user='root';
FLUSH PRIVILEGES;
service mysql restart

Some new version not support above UPDATE query try to use below

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

I'm aware about this problem and when used 16.04 it never happened. And in 18.04, i just tried to use it to resolve.

sudo mysql_secure_installation

In this case, i can set my password, but it does not work

And that code does not solve the problem.

UPDATE user SET password=PASSWORD('NEW_PASSWORD') WHERE user='root';

After the installation just:

  1.  sudo mysql

    (yes, no user no pass)

  2. You are now in the mysql console:

     ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'my_new_pass';
  3. FLUSH PRIVILEGES;

  4. That's it. You can now enter the console next time as usual:

     mysql -u root -p my_new_pass

I tried for about last 24 hours to get rid of those errors and migrate from 16.04 to 18.04 with the same database, but none of all web pages I looked helped me. It was a hell.

Trying systemctl status mysql.service and journalctl -xe was a dead end - no clues.

But the error:

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

lead me to understanding, that mysql-server on 18.04 has a little bit different structure. During installation I had many times seen file like: /etc/mysql/FROZEN.

And only I deeply read it through I understand, that my mistake was coming from different versions of MySQL. It said that I initiated downgrade (from mysql-server-5.7 to mysql-server-5.6), despite I was sure that I did not do it, as I was installing mysql-server-5.7.

The only solution what worked for me was: deleting all files (and databases) from /var/lib/mysql manually and reinstalling mysql-server and mysql-client

I copied them to different location, but than I was unable to restore them. So, the problem was in databases, what could not be migrated. And I also could not find mysql-server-5.6 for Ubuntu 18.04 (I read, that some guy did it by manually compiling). Luckily it was made on test server, so nothing worth were lost. But anyway, next time I will have MySQL db backup before Ubuntu version migrating and make clean install, rather than trying to hold existing databases .

I also had many problems with both MySQL and MariaDB (ubuntu 18.04). I could not get MariaDB to work. I both using instructions at How to forcefully remove MySQL and MariaDB from Ubuntu 16.04, without `apt-get` and `dpkg`?

$ dpkg --list|grep -i mysql 

and

$ dpkg --list|grep -i mariadb

$ dpkg -remove --force-remove-reinstreq <package-list>

Then installed MySQL as described at https://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/

Works well now, even after a reboot. Don't know why this solution is not more widely spread!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM