Start and Stop mysql in Linux, and create database, user in Mysql database

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/mysqld

Jan 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)

From: 

What's NocoDB, NocoDB is an open source platform that turns any database into a smart spreadsheet - #5 by bigdata - Nocodb - Big Data Small Team

--------------------大数据小团队--------------------
蒙昭良:《Oracle DBA高效入门指南》作者
2013-2019: 摩根大通 – 美国哥伦布
2021-目前 : 普华永道 – 北京
大数据小团队论坛

蒙昭良1021×1189 148 KB


--------------------大数据小团队--------------------

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值