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