# install on ubuntu
sudo apt install mysql-server
# install on rasp-pi
sudo apt install mariadb-server-10.0
# 默认mariadb是没有密码的,sudo权限就可以进入
sudo mysql
# sudo mysql -u root -p
# Create New MariaDB User
CREATE USER 'user1'@localhost IDENTIFIED BY 'password1';
# Once you create user1, check its status by entering:
SELECT User FROM mysql.user;
Grant Privileges to MariaDB User
The newly created user does not have privileges to manage databases nor to access the MariaDB shell.
To grant all privileges to user1:
GRANT ALL PRIVILEGES ON *.* TO 'user1'@localhost IDENTIFIED BY 'password1';
The *.*
in the statement refers to the database or table for which the user is given privileges. This specific command provides access to all databases located on the server. As this might be a major security issue, you should replace the symbol with the name of the database you are providing access to.
To grant privileges only for yourDB, type the following statement:
GRANT ALL PRIVILEGES ON 'yourDB'.* TO 'user1'@localhost;
It’s crucial to refresh the privileges once new ones have been awarded with the command:
FLUSH PRIVILEGES;
The user you have created now has full privileges and access to the specified database and tables.
Once you have completed this step, you can verify the new user1 has the right permissions by using the following statement:
SHOW GRANTS FOR 'user1'@localhost;
The information provided by the system is displayed on the terminal.