Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Creating users and assigning permissions to mysql under Linux

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Steps to install mysql on linux

Tools:

mysql-5.6.17-linux-glibc2.5-i686.tar.gz

mysql-5.6.17-linux-glibc2.5-x86_64.tar.gz

Linux 64 bit

method/step

1, to mysql official website download mysql compiled binary installation package.

2. Unzip the installation package:

3. Enter the directory where the installation package is located and execute the command: tar -zxvf mysql-5.6.17-linux-glibc2.5-i686.tar.gz

4. Copy the decompressed mysql directory to the local software directory of the system:

Execute command: cp mysql-5.6.17-linux-glibc2.5-i686 /usr/local/mysql -r

Note: Do not add/at the end of the list

5. Add system mysql group and mysql user:

Execute commands: groupadd mysql and useradd -r -g mysql mysql

6. Install the database:

7. Enter the installation mysql software directory: execute the command cd /usr/local/mysql

8. Modify the current directory owner to mysql user: execute the command chown -R mysql:mysql ./

9. Install database: execute command./ scripts/mysql_install_db --user=mysql

10. Modify the current directory owner to root user: execute the command chown -R root:root ./

11. Modify the current data directory owner to mysql user: execute chown -R mysql:mysql data

This database installation is complete

1. Start mysql service and add startup mysql service:

Add boot: execute cp support-files/mysql.server /etc/init.d/mysql, and put the boot script into the boot initialization directory

Start MySQL service: Execute the command service MySQL start

Execute command: ps -ef| grep mysql see mysql service description started successfully

3. Modify mysql root password, if root initial password is empty:

Execute orders: .../ bin/mysqladmin -u root password 'password'

4. Put the mysql client in the default path:

ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql

Note: It is recommended to use soft chain in the past, do not copy the package file directly, so that the system can install multiple versions of mysql.

Create users and assign permissions to mysql under Linux

1. new user

//Login MYSQL

@>mysql -u root -p

@> Password

//Create user

mysql> insert into mysql.user(Host,User,Password) values('localhost','Tome',password('Tome'));

//Refresh the system permission table

mysql>flush privileges;

This creates a user named: Tome with password: Tome.

//Log in after logging out

mysql>exit;

@>mysql -u Tome -p

@> Enter password

mysql> Login successful

2. Authorize users

//Login to MYSQL (with ROOT privileges). I log in as ROOT.

@>mysql -u root -p

@> Password

//First create a database for users (TomeDB)

mysql>create database TomeDB;

//Authorize jeecn users to have all permissions on the Tome database

@>grant all privileges on TomeDB.* to Tome@localhost identified by 'Tome';

//Refresh the system permission table

mysql>flush privileges;

mysql> Other operations

//If you want to assign partial permissions to a user, you can write:

mysql>grant select,update on TomeDB.* to Tome@localhost identified by 'Tome';

//Refresh the system permissions table.

mysql>flush privileges;

mysql> grant permission 1, permission 2,…permission n on database name. table name to username @ user address identified by 'connection password';

Permission 1, Permission 2, Permission n represents 14 permissions such as select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file, etc.

When privilege 1, privilege 2,…privilege n is replaced by all privileges or all, it means that the user is granted all privileges.

When the database name. Table names are *.* Instead, means that the user is given permission to operate on all tables of all databases on the server.

The user address can be localhost, ip address, machine name, domain name. You can also use '%' to indicate a connection from any address.

'Connection password' cannot be empty, otherwise creation fails.

For example:

mysql>grant select,insert,update,delete,create,drop on vtdc.employee to ee@10.25.197.95 identified by '123′;

Assign user ee from 10.25.197.95 permission to select,insert,update,delete,create,drop, etc. on the employee table of database vtdc, and set password to 123.

mysql>grant all privileges on vtdc.* to jee@10.25.197.95 identified by '123′;

Assign user ee from 10.25.197.95 permission to perform all operations on all tables of database vtdc and set password to 123.

mysql>grant all privileges on *.* to ee@10.25.197.95 identified by '123′;

Assign user ee from 10.25.197.95 permission to perform all operations on all tables of all databases and set password to 123.

mysql>grant all privileges on *.* to ee@localhost identified by '123′;

Assign local user ee permission to perform all operations on all tables of all databases and set password 123.

3. delete user

@>mysql -u root -p

@> Password

mysql>DELETE FROM mysql.user WHERE User="Tome"

mysql>flush privileges;

//delete user database

mysql>drop database TomeDB;

4. Modify the specified user password

@>mysql -u root -p

@> Password

mysql>update mysql.user set password=password ('new password ') where User="Tome" and Host="localhost";

mysql>flush privileges;

mysql>quit;

5. If you cannot connect to the local library using root:

1045 access denied for user 'root'@'localhost' using password yes

Method 1:

# /etc/init.d/mysql stop

# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

# mysql -u root mysql

mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';

mysql> FLUSH PRIVILEGES;

mysql> quit

# /etc/init.d/mysql restart

# mysql -uroot -p

Enter password:

mysql>

Method 2:

Use the username and password provided in the [client] section of the/etc/mysql/debian.cnf file:

# mysql -udebian-sys-maint -p

Enter password:

mysql> UPDATE mysql.user SET Password=PASSWORD('newpassword') where USER='root';

mysql> FLUSH PRIVILEGES;

mysql> quit

# mysql -uroot -p

Enter password:

mysql>

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report