MySQL is a relational SQL database server developed with a focus on high performance. It is multi-threaded, robust, and multi-user. It is open-source software developed under a dual license depending on its use: in an open-source product or in a proprietary product. In the latter case, the license is paid; otherwise, it's free.
$mysql_secure_installation
NOTE:RUNNINGALLPARTSOFTHISSCRIPTISRECOMMENDEDFORALLMySQL
SERVERSINPRODUCTIONUSE!PLEASEREADEACHSTEPCAREFULLY!
InordertologintoMySQLtosecureit,we'll need the currentpassword for the root user. If you'vejustinstalledMySQL,and
youhaven'tsettherootpasswordyet,thepasswordwillbeblank,
soyoushouldjustpressenterhere.
Entercurrentpasswordforroot(enterfornone):
Just press "Enter" because there is no default password
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
You already have a root password set, so you can safely answer 'n'.
Change the root password? [Y/n]
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n]
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n]
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n]
#!/bin/sholddb=olddb
newdb=newdb
user=root
pass='password'port=3306echo"######### COPY / PASTE THOSE LINES TO RENAME DATABASE #########"echo""gettables=`mysql-u\$user\$pass-P\$port-e"show tables from \$olddb;"|grep-v"Tables_in_\$olddb"|grep-v"+"|grep-v"^mysql"|awk'{print \$1}'`foriin`echo\$gettables|tr'\n'' '`;doecho"RENAME TABLE \$olddb.\$i TO \$newdb.\$i;"donemysql-u\$user\$pass-P\$port-e"use \$newdb">/dev/null2>&1||echo"############################ WARNING ##########################\nTHE NEW DATABASE \"\$newdb\" DOES NOT EXIST. please create it first\n###############################################################"
Run this script and it will rename table by table to finally create the new database. This is the method recommended by MySQL.
It can be useful to be able to connect simply without having to enter credentials. Here is a very simple method that consists of entering your credentials in a file in your home:
How to reset your root password when you've lost it?
Have you ever forgotten the root password on one of your MySQL servers? No? Well maybe I'm not as perfect as you. This is a quick h00tow (how to) reset your MySQL root password. It does require root access on your server. If you have forgotten that password wait for another article:
First things first. Log in as root and stop the mysql daemon. Now let's start up the mysql daemon and skip the grant tables which store the passwords.