database_2024<\/strong>. We will create a new database user and its password. Let’s log in to the MySQL command line:<\/p>\n\n\n\n$ mysql -u root -p<\/pre>\n\n\n\nYou will be prompted to type your MySQL root password. Once logged in, you will get into MySQL shell, like this:<\/p>\n\n\n\n
Welcome to the MariaDB monitor. Commands end with ; or \\g.\nYour MariaDB connection id is 31\nServer version: 10.11.4-MariaDB-1~deb12u1 Debian 12\n\nCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.\n\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n\nMariaDB [(none)]><\/pre>\n\n\n\nLet’s run the commands below to create a new MySQL user:<\/p>\n\n\n\n
CREATE USER 'youruser'@'localhost' IDENTIFIED BY 'm0d1fyth15';<\/pre>\n\n\n\nPlease replace m0d1fyth15<\/code> with a stronger password, like a password that does not contain any dictionary words. Next, let\u2019s say we want to give our new user the permission to access only the database ‘database_2024’ on our MySQL server. We can do that by executing the following command:<\/p>\n\n\n\nGRANT ALL ON database_2024.* TO 'youruser'@'localhost';\nFLUSH PRIVILEGES;<\/pre>\n\n\n\nNow, pay attention to the 'youruser'@'localhost'<\/code> part. If you want to give the access from an IP address like 123.123.123.123<\/code>, then you need to replace 'youruser'@'localhost'<\/code> with 'youruser'@'123.123.123.123'<\/code> – the command would look like this:<\/p>\n\n\n\nCREATE USER 'youruser'@'123.123.123.123' IDENTIFIED BY 'm0d1fyth15';\nGRANT ALL ON database_2024.* TO 'youruser'@'123.123.123.123';<\/pre>\n\n\n\nOr, if you want to allow this user to login from any IP address, we can run this command:<\/p>\n\n\n\n
CREATE USER 'youruser'@'%' IDENTIFIED BY 'm0d1fyth15';\nGRANT ALL ON database_2024.* TO 'youruser'@'%';<\/pre>\n\n\n\nThat’s it! You can run the flush privileges command once again.<\/p>\n\n\n\n
If you have a control panel on your server like cPanel or DirectAdmin, you can use their interface to create the MySQL user and whitelist\/allow the IP address you want to connect to MySQL from.<\/p>\n\n\n\n