Friday, January 26, 2024

Personal mysql/mariadb sql command references

Using mysqladmin 

Set password root using mysqladmin

# mysqladmin -u root password

Using mysql client

$ mysql -u [user_name] -p

Show users:

> select User from mysql.user;

Add user:

> create user `test`@`localhost`;
> SELECT User FROM mysql.user;

Set user password

> alter user [user_name] identified by [new_password];

Show database:

> show databases;

Add database:

> create database `test`;
> SHOW DATABASES;
> grant all privileges on test.* to 'test'@'localhost` ;
> flush privileges;

Show table:

> use test;
> show tables;

create table:

> use test;
> create table product(id mediumint, name varchar(100));

Note: Do not use root account to create user table, use particular user to create table.
 


No comments:

Post a Comment