How to install MySQL on Ubuntu 18.04 (linux)

installation

mysql

sudo apt-get--purge remove mysql-server mysql-common mysql-client
sudo apt-get install mysql-server mysql-common mysql-client

mysqladmin -u root password your-new-password
sudo /etc/init.d/mysql restart

mariadb

apt-get install mariadb-server

Character set modification utf8

If you install mariadb, the default character set is already utf8. mysql is not

mysql> show variables like 'char%';+--------------------------+----------------------------+| Variable_name      | Value           |+--------------------------+----------------------------+| character_set_client   | utf8            || character_set_connection | utf8            || character_set_database  | latin1           || character_set_filesystem | binary           || character_set_results  | utf8            || character_set_server   | latin1           || character_set_system   | utf8            || character_sets_dir    |/usr/share/mysql/charsets/|+--------------------------+----------------------------+
mysql> show variables like 'collation%';+----------------------+-------------------+| Variable_name    | Value       |+----------------------+-------------------+| collation_connection | utf8_general_ci  || collation_database  | latin1_swedish_ci || collation_server   | latin1_swedish_ci |+----------------------+-------------------+

Modify the character set:

sudo vim /etc/mysql/my.cnf

Add the following

[ mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8

Restart:

service mysql restart

Login permission issue

After installing mysql or mariadb on Ubuntu 18.04, it is found that ordinary users and remote users have no permission to connect.

ERROR 1045: Access denied for user: ‘root@localhost’ (Using
password: YES)

The password is incorrect. Then sudo mysql -u root can log in. This is obviously not what we want.

solution

Delete root and recreate the user.

First, log in

sudo mysql -u root

Then view the current user

SELECT User,Host FROM mysql.user;+------------------+-----------+| User       | Host   |+------------------+-----------+| admin      | localhost || debian-sys-maint | localhost || magento_user   | localhost || mysql.sys    | localhost || root       | localhost |

Delete root account

mysql> DROP USER 'root'@'localhost';
Query OK,0 rows affected(0,00 sec)

Recreate root:

mysql> CREATE USER 'root'@'%' IDENTIFIED BY '123456';
Query OK,0 rows affected(0,00 sec)

Authorization

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
Query OK,0 rows affected(0,00 sec)

mysql> FLUSH PRIVILEGES;
Query OK,0 rows affected(0,01 sec)

About resetting password

Remote login is allowed when host is %

SET PASSWORD FOR root@'localhost'=PASSWORD('password');

or

UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';

or

USE mysql
UPDATE user SET Password =PASSWORD('newpwd')
WHERE Host ='localhost' AND User ='root';

Allow login anywhere

USE mysql
UPDATE user SET Password =PASSWORD('newpwd')
WHERE Host ='%' AND User ='root';

reference
https://askubuntu.com/questions/766334/cant-login-as-mysql-user-root-from-normal-user-account-in-ubuntu-16-04
https://help.ubuntu.com/community/MysqlPasswordReset

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

How to install MySQL on Ubuntu 18.04 (linux)
How to install MySQL on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install MySQL on Ubuntu 14.04
How to install JDK and Mysql on Ubuntu 18.04 linux system
How to install Oracle Java 14 on Ubuntu Linux
How to install the latest MySQL on Ubuntu 18.04
How to install MySQL on CentOS 8
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install mysql in Ubuntu 14.04
How to install Jenkins on Ubuntu 16.04
How to install MemSQL on Ubuntu 14.04
How to install Go on Ubuntu 20.04
How to install MongoDB on Ubuntu 16.04
How to install Mailpile on Ubuntu 14.04
How to install PrestaShop on Ubuntu 16.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Prometheus on Ubuntu 16.04
How to install Jenkins on Ubuntu 18.04
How to install Apache on Ubuntu 20.04
How to install R on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04
How to install MariaDB on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Mono on Ubuntu 20.04
How to install Go on Ubuntu 20.04
How to install Zoom on Ubuntu 20.04
How to install mysql in Ubuntu 14.04
How to install Nginx on Ubuntu 16.04
How to install OpenCV on Ubuntu 20.04
How to install Spotify on Ubuntu 20.04
How to install Postman on Ubuntu 18.04
How to install Go 1.6 on Ubuntu 16.04
How to install Go on Ubuntu 18.04
How to install PostgreSQL on Ubuntu 20.04
How to install VLC on Ubuntu 18.04
How to install TeamViewer on Ubuntu 20.04
How to install Webmin on Ubuntu 20.04
How to install and use MySQL Workbench on Ubuntu 18.04
Install mysql on Ubuntu 14.04
How to install Bacula Server on Ubuntu 14.04
How to install Ubuntu 19.10 on Raspberry Pi 4
How to install Apache Kafka on Ubuntu 18.04