Table of Contents
MySQL changes root password
MySQL root changes the password of an ordinary user
Delete the default root user of MySQL
Home Database Mysql Tutorial What is the name of the super administrator of mysql database?

What is the name of the super administrator of mysql database?

Jan 06, 2023 pm 03:42 PM
mysql

The super administrator name of the mysql database is "root". When MySQL is installed, a user named root will be created by default. This user has super permissions and can control the entire MySQL server. The root user has very high permissions and can not only change his own password, but also change the passwords of other users.

What is the name of the super administrator of mysql database?

The operating environment of this tutorial: windows7 system, java8 version, DELL G3 computer.

The super administrator name of mysql database is "root".

When MySQL is installed, a user named root will be created by default. This user has super privileges and can control the entire MySQL server.

In the daily management and operation of MySQL, in order to prevent someone from maliciously using the root user to control the database, we usually create some users with appropriate permissions and use the root user as little or as little as possible to log in to the system. to ensure secure access to data.

Generally, the root super administrator has much greater permissions than ordinary users, so some operations require root permissions to run.

The root user has very high permissions and can not only change his own password, but also change the passwords of other users.

MySQL changes root password

In MySQL, the root user has very high permissions, so the security of the root user password must be ensured. There are many ways to change the root user password. This section will introduce several commonly used methods to change the root user password.

  • Modify the user table of the MySQL database

Because all account information is stored in the user table, you can directly Change the root user's password by modifying the user table.

After the root user logs in to the MySQL server, you can use the UPDATE statement to modify the authentication_string field of the user table of the MySQL database to modify the user's password.

The syntax format for using the UPDATA statement to modify the root user password is as follows:

UPDATE mysql.user set authentication_string = PASSWORD ("rootpwd) WHERE User = "root" and Host="localhost";
Copy after login

The new password must be encrypted using the PASSWORD() function. After executing the UPDATE statement, you need to execute the FLUSH PRIVILEGES statement to reload user permissions.

  • Use the SET statement to modify the password of the root user

The SET PASSWORD statement can be used to reset the login of other users Password or the password of the account you use. The syntax structure of using the SET statement to change the password is as follows:

SET PASSWORD = PASSWORD ("rootpwd");
Copy after login

MySQL root changes the password of an ordinary user

  • Using the SET statement to change the password of an ordinary user

In MySQL, only the root user can change the password by updating the MySQL database. After logging in to the MySQL server as the root user, you can use the SET statement to modify the ordinary user password. The syntax format is as follows:

SET PASSWORD FOR 'username'@'hostname' = PASSWORD ('newpwd');
Copy after login

Among them, the username parameter is the user name of an ordinary user, the hostname parameter is the host name of an ordinary user, and newpwd is the new password to be changed.

Note: The new password must be encrypted using the PASSWORD() function. If it is not encrypted using PASSWORD(), it will be executed successfully, but the user will not be able to log in.

If an ordinary user changes the password, you can omit the FOR clause to change your own password. The syntax format is as follows:

SET PASSWORD = PASSWORD('newpwd');
Copy after login

Example 1

After the root user logs in to the MySQL server, use the SET statement to change the password of the testuser user to "newpwd". The SQL statement and running results are as follows:

mysql> SET PASSWORD FOR 'testuser'@'localhost' = PASSWORD("newpwd");
Query OK, 0 rows affected, 1 warning (0.01 sec)
Copy after login

It can be seen from the running results that the SET statement was successfully executed and the password of the testuser user was successfully set to "newpwd".

  • Use the UPDATE statement to modify the password of an ordinary user

After logging in to the MySQL server as the root user, you can use the UPDATE statement Modify the authentication_string field of the user table of the MySQL database to modify the password of an ordinary user. The syntax of the UPDATA statement is as follows:

UPDATE MySQL.user SET authentication_string = PASSWORD("newpwd") WHERE User = "username" AND Host = "hostname";
Copy after login

Among them, the username parameter is the user name of an ordinary user, the hostname parameter is the host name of an ordinary user, and newpwd is the new password to be changed.

Note that after executing the UPDATE statement, you need to execute the FLUSH PRIVILEGES statement to reload user permissions.

Example 3

Use the root user to log in to the MySQL server, and then use the UPDATE statement to change the testuser user's password to "newpwd2". The SQL statement and running results are as follows:

mysql> UPDATE MySQL.user SET authentication_string = PASSWORD ("newpwd2")
    -> WHERE User = "testuser" AND Host = "localhost";
Query OK, 1 row affected, 1 warning (0.07 sec)
Rows matched: 1  Changed: 1  Warnings: 1
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.03 sec)
Copy after login

It can be seen from the running results that the password was changed successfully. The password of testuser was changed to newpwd2. After reloading the permissions using FLUSH PRIVILEGES, you can log in to the testuser user with the new password.

Delete the default root user of MySQL

Requirement analysis:

  • The root password appears in many places, such as sharing Technical documents, emails, screenshots.

  • The default administrator account name for MySQL installation is root, which is well known. In order to enhance security, you need to change a user name, such as superuser, or have Company-specific. For example, xxx_admin.

Countermeasures:

  • First create a user with the same permissions as the root user.

GRANT ALL PRIVILEGES ON *.* TO 'x_admin'@'127.0.0.1' IDENTIFIED BY 'xxxx';
Copy after login
  • 删除默认的root用户.

drop user root@'127.0.0.1';
drop user root@'localhost';
drop user root@'::1';
Copy after login

用户账号:

格式为 user_name'@'host_name。

这里的user_name是用户名,host_name为主机名,即用户连接 MySQL 时所用主机的名字。

如果在创建的过程中,只给出了用户名,而没指定主机名,那么主机名默认为“%”,表示一组主机,即对所有主机开放权限。

注意问题:

1、视图

曾经用root帐号为DEFINER的视图,如果将root删除,将提示该视图无法使用,没有权限.所以要注意提前查看是否存在视图,存在的话,需要修改该视图的DEFINER属性.

修改视图,是瞬间就能完成的操作,除非该视图被其他sql语句占用,处于锁定的状态.

查看视图

select TABLE_SCHEMA, TABLE_NAME, VIEW_DEFINITION, DEFINER from information_schema.VIEWS;
Copy after login

修改视图(非root的暂不修改)

ALTER DEFINER=`x_admin`@`127.0.0.1` SQL SECURITY DEFINER VIEW v_name AS...
Copy after login

2、存储过程/函数

情况与视图类似

查看存储过程/视图

select ROUTINE_SCHEMA,ROUTINE_NAME,ROUTINE_TYPE,DEFINER from information_schema.ROUTINES;
Copy after login

或者

select db,name,type,definer from mysql.proc;
Copy after login

修改存储例程,可直接修改mysql.proc

update mysql.proc set definer='x_admin@127.0.0.1'where db='db_name';
Copy after login

如果修改所有库

update mysql.proc set definer='x_admin@127.0.0.1';
Copy after login

2、用root用户连接MySQL的脚本

此类问题比较好解决,可单独为脚本创建帐号用来执行脚本中指定的操作,该用户名可用script_,或者脚本名命名.权限够用就行,不要分配过多的权限.

4、方法:一个增加用户的脚本.(配合批量执行)

#!/usr/bin/python
#-*- coding: UTF-8 -*-
# ########################################################################
# This program
# Version: 2.0.0 (2012-10-10)
# Authors: lianjie.ning@qunar.com
# History:
# ########################################################################

import os
import socket
import subprocess
import sys
import traceback
from ConfigParser import ConfigParser

class Finger(object):
   'finger.py'

   def __init__ (self):
       print '---- %s, %s' % (socket.gethostname(), self.__doc__)

   def load_config (self, file="finger.ini"):
       if not os.path.exists(file):
           print file,"is not exists, but is created, please fix it"
           temp_ini = '''[conn_db]
login_pwd =
exec_sql =
'''
           open(file, 'w').write(temp_ini)
           os.chmod(file, 0600)
           sys.exit()
       config = ConfigParser()
       config.read(file)
       if config.has_section('conn_db') is True:
           if config.has_option('conn_db', 'login_pwd') is True:
               login_pwd = config.get('conn_db', 'login_pwd')
           if config.has_option('conn_db', 'exec_sql') is True:
               exec_sql = config.get('conn_db', 'exec_sql')
           return (login_pwd, exec_sql)

   def grant_user(self, login_pwd, exec_sql):
       if os.path.exists('/usr/local/bin/mysql'):
           mysql = '/usr/local/bin/mysql'
       elif os.path.exists('/usr/bin/mysql'):
           mysql = '/usr/bin/mysql'
       elif os.path.exists('/bin/mysql'):
           mysql = '/bin/mysql'
       else:
           print "command not fount of mysql"
           sys.exit()

       user = 'xxxx'
       conn_port = [3306,3307,3308,3309,3310]
       for i in conn_port:
           ss = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
           address = ('127.0.0.1', int(i))
           status = ss.connect_ex(address)
           ss.settimeout(3)
           ss.close()
           if status == 0:
               conn_mysql  = '%s -u%s -p%s -h127.0.0.1 -P%d -N -s -e"%s"' % (mysql, user, login_pwd, i, exec_sql)
               p = subprocess.call(conn_mysql, shell=True, stdout=open("/dev/null"))
               if p == 0:
                   print "---- checking port: %s is NORMAL" % i
               else:
                   print "---- checking prot: %s is ERROR" % i

if __name__ == '__main__':
   try:
       process = Finger()
       (login_pwd, exec_sql) = process.load_config()
       process.grant_user(login_pwd, exec_sql)
   except Exception, e:
       print str(e)
       traceback.print_exc()
       sys.exit()
Copy after login

【相关推荐:mysql视频教程

The above is the detailed content of What is the name of the super administrator of mysql database?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1252
24
Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

Solve MySQL mode problem: The experience of using the TheliaMySQLModesChecker module Solve MySQL mode problem: The experience of using the TheliaMySQLModesChecker module Apr 18, 2025 am 08:42 AM

When developing an e-commerce website using Thelia, I encountered a tricky problem: MySQL mode is not set properly, causing some features to not function properly. After some exploration, I found a module called TheliaMySQLModesChecker, which is able to automatically fix the MySQL pattern required by Thelia, completely solving my troubles.

MySQL: Structured Data and Relational Databases MySQL: Structured Data and Relational Databases Apr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities Explained MySQL: Key Features and Capabilities Explained Apr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

See all articles