How to change the root password and enable and disable MySql in Linux

Source: Internet
Author: User
Tags mysql gui mysql gui tools
Document directory
  • Introduction to important Linux MySQL directories and logon passwords
  • Introduction to important Linux MySQL directories and logon passwords

Before giving you a detailed introduction to Linux MySQL, first let you know about Linux MySQL, and then give a comprehensive introduction to Linux MySQL, hoping to be useful to you.

1. Linux MySQL installation:
$ Yum install mysql-Server

2. Change the root password for Linux MYSQL:
$ Mysqladmin-u Root Password your_new_passwd

3. Start the Linux MySQL Service
$/Etc/init. d/mysqld start

4. Add as a system service and start it automatically:
$ Chkconfig -- level 2345 mysqld on

5. Modify the firewall and enable port 3306 for remote access:
System-> Administration-> firewall-> other ports, add Port 3306, make sure to add both TCP and UDP!

In essence, the/etc/sysconfig/iptables file can be modified directly in the following format:
-A input-M state -- state new-m tcp-p tcp -- dport 3306-J accept
-A input-M state -- state new-m tcp-p udp -- dport 3306-J accept

6. By default, the root user of MySQL cannot be remotely accessed. You need to add a remote access user to Linux mysql. First, log on to Linux MYSQL as the root user and add a user:
Grant all on *. * To your_username @ 'your _ host_name_or_ip_address 'identified by 'your _ password'

All indicates all permissions (including adding, deleting, modifying, and so on ),*. * indicates any table in any database. It can also be defined as a database or even a table in Linux mysql. After logon, the user can only perform the operation just given to the database. Your_host_name_or_ip_address indicates that you can only remotely access the IP address. If any address can be accessed, it can be replaced by a wildcard %.

For example, grant insert on test. * Identified by 'test' indicates that you can log on to the test database by using the user name test and password test on any IP address. After logon, you can only insert the test database.

In essence, Linux MySQL contains a database of Linux MySQL by default, with a user table. The above grant Command actually adds a row of records to this table. You can also directly modify the expression to the same effect, but it is more troublesome. Note that you can use the password () function to add a password.

7. Remote logon. Take Linux as an example (MySQL GUI tools can be used in Windows ):
$ Mysql-U test-H 192.168.1.111-P # enter the password.

8. Solve the Problem of garbled characters when inserting Chinese characters into the database table:
1) modify the/etc/My. CNF file, find [mysqld], and add the following lines to the end:
Default-character-set = utf8
Create a new item named [client] and insert the same statement as above. Restart the Linux MySQL service.
2) To create an SQL script for a database, add the following statement:
Drop database if exists test;
Create Database test default Character Set utf8;
As a result, the default character set for Linux MySQL is set to the UTF-8, the character set for the created table also changes to the UTF-8, and the client will also be displayed in the UTF-8.

 

Introduction to important Linux MySQL directories and logon passwords

It is particularly worth mentioning that there are many things worth learning about Linux mysql. Here we mainly introduce Linux MySQL, including various aspects of Linux MySQL. Linux MySQL is not installed in a directory by default after installation. Its database files, configuration files, and command files are in different directories. It is very important to understand these directories, especially for Linux beginners, the directory structure of Linux itself is complicated. If you do not know the installation directory of Linux MySQL, you will not be able to learn it in depth.

The following describes these directories.

Important directories of Linux MySQL

1. Database directory
/Var/lib/MySQL/
2. Configuration File
/Usr/share/MySQL (MySQL. server command and configuration file)
3. Related commands
/Usr/bin (commands such as mysqladmin mysqldump)
4. Start the script
/Etc/rc. d/init. d/(directory for starting the script file MySQL)

Changing the logon password for Linux MySQL

Linux MySQL does not have a password by default. It is self-evident that the password is added after installation.

1. Commands
Usr/bin/mysqladmin-u Root Password 'new-password'
Format: mysqladmin-u username-P old Password New Password

2. Example
Example 1: Add a 123456 password to the root user.
Type the following command:
[Root @ test1 local] #/usr/bin/mysqladmin-u Root Password 123456
Note: because the root account does not have a password at the beginning, the old-P password can be omitted.

3. test whether the modification is successful
1) login without a password
[Root @ test1 local] # MySQL
Error 1045: Access denied for user: 'root @ localhost' (using password: No)
An error is displayed, indicating that the password has been modified.
2) log on with the modified Password
[Root @ test1 local] # mysql-u root-P
Enter Password: (enter the password 123456 after modification)
Welcome to the MySQL monitor. commands end with; or/g.
Your MySQL connection ID is 4 to server version: 4.0.16-Standard
Type 'help; 'or'/H' for help. type'/C' to clear the buffer.
Mysql>
Successful! You can use the mysqladmin command to change the password or the database to change the password.

Linux MySQL Start and Stop

1. Start
After MySQL is installed, run the following command to start MySql in the/etc/init. d directory.
[Root @ test1 init. d] #/etc/init. d/MySQL start another installer installs MySQL as a service, so you can use # service MySQL start to start Linux MySql in any directory.
2. Stop
/Usr/bin/mysqladmin-u root-P shutdown or: # service MySQL stop
3. Automatic Start
1) Check whether MySQL is in the Auto Start List
[Root @ test1 local] #/sbin/chkconfig-list
2) Add Linux MySQL to the startup Service Group of your system.
[Root @ test1 local] #/sbin/chkconfig-add MySQL
3) Delete Linux MySQL from the startup Service Group.
[Root @ test1 local] #/sbin/chkconfig-del MySQL

Before giving you a detailed introduction to Linux MySQL, first let you know about Linux MySQL, and then give a comprehensive introduction to Linux MySQL, hoping to be useful to you.

1. Linux MySQL installation:
$ Yum install mysql-Server

2. Change the root password for Linux MYSQL:
$ Mysqladmin-u Root Password your_new_passwd

3. Start the Linux MySQL Service
$/Etc/init. d/mysqld start

4. Add as a system service and start it automatically:
$ Chkconfig -- level 2345 mysqld on

5. Modify the firewall and enable port 3306 for remote access:
System-> Administration-> firewall-> other ports, add Port 3306, make sure to add both TCP and UDP!

In essence, the/etc/sysconfig/iptables file can be modified directly in the following format:
-A input-M state -- state new-m tcp-p tcp -- dport 3306-J accept
-A input-M state -- state new-m tcp-p udp -- dport 3306-J accept

6. By default, the root user of MySQL cannot be remotely accessed. You need to add a remote access user to Linux mysql. First, log on to Linux MYSQL as the root user and add a user:
Grant all on *. * To your_username @ 'your _ host_name_or_ip_address 'identified by 'your _ password'

All indicates all permissions (including adding, deleting, modifying, and so on ),*. * indicates any table in any database. It can also be defined as a database or even a table in Linux mysql. After logon, the user can only perform the operation just given to the database. Your_host_name_or_ip_address indicates that you can only remotely access the IP address. If any address can be accessed, it can be replaced by a wildcard %.

For example, grant insert on test. * Identified by 'test' indicates that you can log on to the test database by using the user name test and password test on any IP address. After logon, you can only insert the test database.

In essence, Linux MySQL contains a database of Linux MySQL by default, with a user table. The above grant Command actually adds a row of records to this table. You can also directly modify the expression to the same effect, but it is more troublesome. Note that you can use the password () function to add a password.

7. Remote logon. Take Linux as an example (MySQL GUI tools can be used in Windows ):
$ Mysql-U test-H 192.168.1.111-P # enter the password.

8. Solve the Problem of garbled characters when inserting Chinese characters into the database table:
1) modify the/etc/My. CNF file, find [mysqld], and add the following lines to the end:
Default-character-set = utf8
Create a new item named [client] and insert the same statement as above. Restart the Linux MySQL service.
2) To create an SQL script for a database, add the following statement:
Drop database if exists test;
Create Database test default Character Set utf8;
As a result, the default character set for Linux MySQL is set to the UTF-8, the character set for the created table also changes to the UTF-8, and the client will also be displayed in the UTF-8.

 

Introduction to important Linux MySQL directories and logon passwords

It is particularly worth mentioning that there are many things worth learning about Linux mysql. Here we mainly introduce Linux MySQL, including various aspects of Linux MySQL. Linux MySQL is not installed in a directory by default after installation. Its database files, configuration files, and command files are in different directories. It is very important to understand these directories, especially for Linux beginners, the directory structure of Linux itself is complicated. If you do not know the installation directory of Linux MySQL, you will not be able to learn it in depth.

The following describes these directories.

Important directories of Linux MySQL

1. Database directory
/Var/lib/MySQL/
2. Configuration File
/Usr/share/MySQL (MySQL. server command and configuration file)
3. Related commands
/Usr/bin (commands such as mysqladmin mysqldump)
4. Start the script
/Etc/rc. d/init. d/(directory for starting the script file MySQL)

Changing the logon password for Linux MySQL

Linux MySQL does not have a password by default. It is self-evident that the password is added after installation.

1. Commands
Usr/bin/mysqladmin-u Root Password 'new-password'
Format: mysqladmin-u username-P old Password New Password

2. Example
Example 1: Add a 123456 password to the root user.
Type the following command:
[Root @ test1 local] #/usr/bin/mysqladmin-u Root Password 123456
Note: because the root account does not have a password at the beginning, the old-P password can be omitted.

3. test whether the modification is successful
1) login without a password
[Root @ test1 local] # MySQL
Error 1045: Access denied for user: 'root @ localhost' (using password: No)
An error is displayed, indicating that the password has been modified.
2) log on with the modified Password
[Root @ test1 local] # mysql-u root-P
Enter Password: (enter the password 123456 after modification)
Welcome to the MySQL monitor. commands end with; or/g.
Your MySQL connection ID is 4 to server version: 4.0.16-Standard
Type 'help; 'or'/H' for help. type'/C' to clear the buffer.
Mysql>
Successful! You can use the mysqladmin command to change the password or the database to change the password.

Linux MySQL Start and Stop

1. Start
After MySQL is installed, run the following command to start MySql in the/etc/init. d directory.
[Root @ test1 init. d] #/etc/init. d/MySQL start another installer installs MySQL as a service, so you can use # service MySQL start to start Linux MySql in any directory.
2. Stop
/Usr/bin/mysqladmin-u root-P shutdown or: # service MySQL stop
3. Automatic Start
1) Check whether MySQL is in the Auto Start List
[Root @ test1 local] #/sbin/chkconfig-list
2) Add Linux MySQL to the startup Service Group of your system.
[Root @ test1 local] #/sbin/chkconfig-add MySQL
3) Delete Linux MySQL from the startup Service Group.
[Root @ test1 local] #/sbin/chkconfig-del MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.