Step 1: Install mysql client and server in the first step. Become root by typing “su -” at a terminal
yum install mysql mysql-serverAfter the installation you can restart the mysql-server by doing this
/etc/init.d/mysqld restartNext you need to setup the root password for the server, start the setup process by doing this
mysql_secure_installationYou would be asked for the current root password which is blank to begin with, next you would be asked to set the new root password for the mysql server, after which you would be asked a few Y/n questions, answers to which are not difficult to guess. I chose Y for all of them.
mysqladmin command to change root password
If you have never set a root password for MySQL, the server does not require a password at all for connecting as root. To setup root password for first time, use mysqladmin command at shell prompt as follows:
$ mysqladmin -u root password NEWPASSWORDHowever, if you want to change (or update) a root password, then you need to use following command
$ mysqladmin -u root -p'oldpassword' password newpassFor example, If old password is abc, and set new password to 123456, enter:
$ mysqladmin -u root -p'abc' password '123456'Change MySQL password for other user
To change a normal user password you need to type (let us assume you would like to change password for vivek):
$ mysqladmin -u vivek -p oldpassword password newpassChanging MySQL root user password using MySQL sql command
This is another method. MySQL stores username and passwords in user table inside MySQL database. You can directly update password using the following method to update or change password for user vivek:
1) Login to mysql server, type following command at shell prompt:
$ mysql -u root -p2) Use mysql database (type command at mysql> prompt):
mysql> use mysql;3) Change password for user vivek:
mysql> update user set password=PASSWORD("NEWPASSWORD") where User='vivek';4) Reload privileges:
mysql> flush privileges; mysql> quitHow to start mysql as a service?service mysqld startHow to start at startup time?chkconfig mysqld on A) If you are using mysql on RedHat Linux (Fedora Core/Cent OS) then use following command:
* To start mysql server:
/etc/init.d/mysqld start* To stop mysql server:
/etc/init.d/mysqld stop* To restart mysql server
/etc/init.d/mysqld restartTip: Redhat Linux also supports service command, which can be use to start, restart, stop any service:
# service mysqld start # service mysqld stop # service mysqld restartTroubleshooting: Sometimes, two similar packages coexist on the repository.
- yum list mysql-server*
Installed Packages
mysql-server.x86_64 5.0.77-4.el5_4.2 installed
Available Packages
MySQL-server-community.x86_64 5.1.24-0.rhel5 DEVLAB-ams-misc-x86-64
Since one has a higher release number than the other it will be picked up first during install. The way to install the previous version would be to run the 'disablerepo' option:
- yum remove MySQL-server-community.x86_64
- yum list mysql-server*
- yum install mysql-server.x86_64 --disablerepo DEVLAB-ams-misc-x86-64
First, use the mysql program to connect to the server as the MySQL
root user:shell> mysql --user=root mysql
If you have assigned a password to the
root account, you will also need to supply a --password or -p option, both for this mysql command and for those later in this section.After connecting to the server as
root, you can add new accounts. The following statements use GRANT to set up four new accounts:mysql>CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';mysql>GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'->WITH GRANT OPTION;mysql>CREATE USER 'monty'@'%' IDENTIFIED BY 'some_pass';mysql>GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'->WITH GRANT OPTION;mysql>CREATE USER 'admin'@'localhost';mysql>GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost';mysql>CREATE USER 'dummy'@'localhost';
The accounts created by these statements have the following properties:
- Two of the accounts have a user name of
montyand a password ofsome_pass. Both accounts are superuser accounts with full privileges to do anything. The'monty'@'localhost'account can be used only when connecting from the local host. The'monty'@'%'account uses the'%'wildcard for the host part, so it can be used to connect from any host.It is necessary to have both accounts formontyto be able to connect from anywhere asmonty. Without thelocalhostaccount, the anonymous-user account forlocalhostthat is created by mysql_install_db would take precedence whenmontyconnects from the local host. As a result,montywould be treated as an anonymous user. The reason for this is that the anonymous-user account has a more specificHostcolumn value than the'monty'@'%'account and thus comes earlier in theusertable sort order. (usertable sorting is discussed inSection 5.4.4, “Access Control, Stage 1: Connection Verification”.) - The
'admin'@'localhost'account has no password. This account can be used only byadminto connect from the local host. It is granted theRELOADandPROCESSadministrative privileges. These privileges enable theadminuser to execute the mysqladmin reload, mysqladmin refresh, and mysqladmin flush-xxxcommands, as well as mysqladmin processlist . No privileges are granted for accessing any databases. You could add such privileges later by issuing otherGRANTstatements. - The
'dummy'@'localhost'account has no password. This account can be used only to connect from the local host. No privileges are granted. It is assumed that you will grant specific privileges to the account later.
The statements that create accounts with no password will fail if the
NO_AUTO_CREATE_USER SQL mode is enabled. To deal with this, use an IDENTIFIED BY clause that specifies a nonempty password.To check the privileges for an account, use
SHOW GRANTS:mysql> SHOW GRANTS FOR 'admin'@'localhost';
+-----------------------------------------------------+
| Grants for admin@localhost |
+-----------------------------------------------------+
| GRANT RELOAD, PROCESS ON *.* TO 'admin'@'localhost' |
+-----------------------------------------------------+
No comments:
Post a Comment