Mysql method to delete the root user: 1. Use the "CREATE USER" statement to create a user with the same permissions as the root user; 2. Use the "drop user" statement to delete the root user, with the syntax "DROP USER root user account ".
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
Delete MySQL’s default root user
Requirements analysis:
The root password is in multiple It has appeared in places, such as shared technical documents, emails, and screenshots.
The administrator account name root installed by MySQL by default is well known. In order to enhance security, a user name needs to be changed, for example Change to superuser, or one with company characteristics. 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';
Delete the default root user.
drop user root@'127.0.0.1'; drop user root@'localhost'; drop user root@'::1';
User account:
The format is user_name'@'host_name.
The user_name here is the user name, and host_name is the host name, which is the name of the host used by the user to connect to MySQL.
If during the creation process, only the user name is given but no host name is specified, the host name defaults to "%", which means a group of hosts, that is, permissions are open to all hosts.
Attention:
1. View
The view that once used the root account as DEFINER will be prompted if root is deleted. The view cannot be used and has no permissions. Therefore, pay attention to check in advance whether the view exists. If it exists, you need to modify the DEFINER attribute of the view.
Modifying the view can be completed in an instant, unless the view is used by other sql The statement is occupied and is in a locked state.
View view
select TABLE_SCHEMA, TABLE_NAME, VIEW_DEFINITION, DEFINER from information_schema.VIEWS;
Modify the view (non-root ones will not be modified temporarily)
ALTER DEFINER=`x_admin`@`127.0.0.1` SQL SECURITY DEFINER VIEW v_name AS...
2. Stored procedure/function
The situation is similar to that of views
View stored procedures/views
select ROUTINE_SCHEMA,ROUTINE_NAME,ROUTINE_TYPE,DEFINER from information_schema.ROUTINES;
or
select db,name,type,definer from mysql.proc;
Modify stored routines, you can directly modify mysql.proc
update mysql.proc set definer='x_admin@127.0.0.1'where db='db_name';
If you modify all libraries
update mysql.proc set definer='x_admin@127.0.0.1';
2. Use the root user to connect to the MySQL script
This kind of problem is easier to solve. You can create a separate account for the script to perform the operations specified in the script. , the user name can be named script_, or the script name. The permissions are enough, do not assign too many permissions.
4. Method: a script to add users. (Cooperate with batch execution)
#!/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()
【Related recommendations: mysql video tutorial】
The above is the detailed content of How to delete root user in mysql. For more information, please follow other related articles on the PHP Chinese website!

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

Efficient methods for batch inserting data in MySQL include: 1. Using INSERTINTO...VALUES syntax, 2. Using LOADDATAINFILE command, 3. Using transaction processing, 4. Adjust batch size, 5. Disable indexing, 6. Using INSERTIGNORE or INSERT...ONDUPLICATEKEYUPDATE, these methods can significantly improve database operation efficiency.

In MySQL, add fields using ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column, delete fields using ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop. When adding fields, you need to specify a location to optimize query performance and data structure; before deleting fields, you need to confirm that the operation is irreversible; modifying table structure using online DDL, backup data, test environment, and low-load time periods is performance optimization and best practice.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1
Easy-to-use and free code editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
