How to change the root’s password in MySQL
root@SecondaryDataUse:~/nocodb/docker-compose/mysql# pwd
/root/nocodb/docker-compose/mysql
root@SecondaryDataUse:~/nocodb/docker-compose/mysql# sudo mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 46
Server version: 8.0.27-0ubuntu0.20.04.1 (Ubuntu)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'my_root_password';
Query OK, 0 rows affected (0.06 sec)
mysql>
How to stop/start the mysql service on Linux Ubuntu20.04
root@SecondaryDataUse:~/nocodb/docker-compose/mysql# pwd
/root/nocodb/docker-compose/mysql
root@SecondaryDataUse:~/nocodb/docker-compose/mysql# sudo mysql
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)
root@SecondaryDataUse:~/nocodb/docker-compose/mysql# mysql --version
mysql Ver 8.0.27-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
root@SecondaryDataUse:~/nocodb/docker-compose/mysql# mysql
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)
root@SecondaryDataUse:~/nocodb/docker-compose/mysql# sudo systemctl stop mysql
root@SecondaryDataUse:~/nocodb/docker-compose/mysql#root@SecondaryDataUse:~/nocodb/docker-compose/mysql# sudo systemctl start mysql
root@SecondaryDataUse:~/nocodb/docker-compose/mysql# sudo systemctl status mysql
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2022-01-27 16:09:35 CST; 7s ago
Process: 211424 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 211463 (mysqld)
Status: “Server is operational”
Tasks: 38 (limit: 4654)
Memory: 392.9M
CGroup: /system.slice/mysql.service
└─211463 /usr/sbin/mysqldJan 27 16:09:33 SecondaryDataUse systemd[1]: Starting MySQL Community Server…
Jan 27 16:09:35 SecondaryDataUse systemd[1]: Started MySQL Community Server.
root@SecondaryDataUse:~/nocodb/docker-compose/mysql#
How to login the mysql with user and password from Linux terminal:
root@SecondaryDataUse:~/nocodb/docker-compose/mysql# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.27-0ubuntu0.20.04.1 (Ubuntu)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql>
Create Mysql database, user, and grant user to database.
mysql> create database root_db;
Query OK, 1 row affected (0.02 sec)
mysql> show databases;
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+--------------------------------------+--------+
7 rows in set (0.01 sec)
mysql> SET GLOBAL validate_password.length = 4;
Query OK, 0 rows affected (0.00 sec)
mysql> SET GLOBAL validate_password.policy=LOW;
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE USER 'noco'@'localhost' IDENTIFIED BY 'enjoypassword';
Query OK, 0 rows affected (0.01 sec)
mysql> GRANT ALL PRIVILEGES ON root_db.* TO 'noco'@'localhost';
Query OK, 0 rows affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| root_db |
| sys |
+--------------------+
5 rows in set (0.00 sec)
--------------------大数据小团队--------------------
蒙昭良:《Oracle DBA高效入门指南》作者
2013-2019: 摩根大通 – 美国哥伦布
2021-目前 : 普华永道 – 北京
大数据小团队论坛
--------------------大数据小团队--------------------