Install mysql on CentOS and set it to open to the outside world

Source: Internet
Author: User

Install mysql on CentOS and set it to open to the outside world

Http://cdn.mysql.com/Downloads/MySQLGUITools/mysql-workbench-community-6.1.6-1.el6.x86_64.rpm

Http://dev.mysql.com/get/Downloads/MySQLGUITools/mysql-workbench-community-6.1.6-1.el6.i686.rpm


Yum insatll server-client-share.rpms ---------------> install mysql






Mysql_install_db -------------> put db into/var/lib/mysql


Mysqld_safe -- skip-grant-tables ---------------> clean all password seted before
Mysql-u root
Select host, user, password from user;
Update user set password = ''where user = 'root ';
Flush privileges;


Mysqld_safe & --------------> set your password
Mysql-u root
Use mysql;
ERROR 1820 (HY000): You must set password before executing this statement
Mysql> set password = PASSWORD ('20140901 ');
Quit


Mysql-u root-p -----------------> make ssh can user your dababases;
1314521
Mysql> show databases;
+ -------------------- +
| Database |
+ -------------------- +
| Information_schema |
| Mysql |
| Performance_schema |
| Test |
+ -------------------- +
4 rows in set (0.00 sec)


Mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with-


Database changed
Mysql> select host, user, password from user;
+ ----------------------- + ------ + ------------------------------------------- +
| Host | user | password |
+ ----------------------- + ------ + ------------------------------------------- +
| Localhost | root | * C2864CD5380E51682CE85D0D54D3AD556F9C1E08 |
| Localhost. localdomain | root |
| 127.0.0.1 | root |
|: 1 | root |
+ ----------------------- + ------ + ------------------------------------------- +
4 rows in set (0.00 sec)


Mysql> create user 'root' @ '% ';
Query OK, 0 rows affected (0.00 sec)


Mysql> grant all privileges on *. * to 'root' @ '% ';
Query OK, 0 rows affected (0.00 sec)


Mysql> select host, user, password from user;
+ ----------------------- + ------ + ------------------------------------------- +
| Host | user | password |
+ ----------------------- + ------ + ------------------------------------------- +
| Localhost | root | * C2864CD5380E51682CE85D0D54D3AD556F9C1E08 |
| Localhost. localdomain | root |
| 127.0.0.1 | root |
|: 1 | root |
| % | Root |
+ ----------------------- + ------ + ------------------------------------------- +
5 rows in set (0.00 sec)


Mysql> grant all privileges on *. * to 'root' @ '% 'identified by '123 ';


// Grant all privileges on ydjj_cnAll. * to 'ydjj' @ '%' identified by '123'
Query OK, 0 rows affected (0.00 sec)


Mysql> select host, user, password from user;
+ ----------------------- + ------ + ------------------------------------------- +
| Host | user | password |
+ ----------------------- + ------ + ------------------------------------------- +
| Localhost | root | * C2864CD5380E51682CE85D0D54D3AD556F9C1E08 |
| Localhost. localdomain | root |
| 127.0.0.1 | root |
|: 1 | root |
| % | Root | * C2864CD5380E51682CE85D0D54D3AD556F9C1E08 |
+ ----------------------- + ------ + ------------------------------------------- +
5 rows in set (0.00 sec)


Mysql>




// Mysql_secure_installation
















After installing mysql-server, you will be prompted to run mysql_secure_installation. Running mysql_secure_installation will execute several settings:
A) set a password for the root user
B) Delete anonymous accounts
C. Cancel the remote Logon of the root user.
D) Delete the test database and access permissions to the test database.
E) refresh the authorization table to make the modification take effect.


These settings can improve the security of the mysql database. We recommend that you run mysql_secure_installation once mysql is installed in the production environment. For detailed steps, see the following command:


Copy the Code as follows:


[Root @ server1 ~] # Mysql_secure_installation
NOTE: running all parts of this script is recommended for all MySQL
Servers in production use! Please read each step carefully!
In order to log into MySQL to secure it, we'll need the current
Password for the root user. If you 've just installed MySQL, and
You haven't set the root password yet, the password will be blank,
So you shoshould just press enter here.
Enter current password for root (enter for none ):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
Root user without the proper authorisation.
Set root password? [Y/n] <-whether to set the root user password. Enter y and press ENTER or press Enter.
New password: <-set the password of the root user
Re-enter new password: <-enter your password again
Password updated successfully!
Reloading privilege tables ..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
To log into MySQL without having to have a user account created
Them. This is intended only for testing, and to make the installation
Go a bit smoother. You shoshould remove them before moving into
Production environment.
Remove anonymous users? [Y/n] <-whether to delete anonymous users. It is recommended to delete anonymous users in the production environment. Press enter.
... Success!
Normally, root shoshould 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] <-whether to disable remote root login. Select Y/n as needed and press Enter. We recommend that you disable
... Success!
By default, MySQL comes with a database named 'test' that anyone can
Access. This is also intended only for testing, and shocould be removed
Before moving into a production environment.
Remove test database and access to it? [Y/n] <-whether to delete the test database. Press enter.
-Dropping test database...
... Success!
-Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
Will take effect immediately.
Reload privilege tables now? [Y/n] <-whether to reload the permission table. Press enter.
... Success!
Cleaning up...
All done! If you 've completed all of the above steps, your MySQL
Installation shoshould now be secure.
Thanks for using MySQL!
[Root @ server1 ~] #








Open the terminal and enter:
Yum install mysql-server


Create a system startup link for MySQL (MySQL will automatically start when the system starts) and enter the following command on the terminal:
Chkconfig -- levels 235 mysqld on


/Etc/init. d/mysqld start


Set the password for the MySQL root Account:
Mysql_secure_installation


Terminal display, follow the prompts:



[Root @ server1 ~] # Mysql_secure_installation


NOTE: running all parts of this script is recommended for all MySQL
Servers in production use! Please read each step carefully!


In order to log into MySQL to secure it, we'll need the current
Password for the root user. If you 've just installed MySQL, and
You haven't set the root password yet, the password will be blank,
So you shoshould just press enter here.


Enter current password for root (enter for none ):
OK, successfully used password, moving on...


Setting the root password ensures that nobody can log into the MySQL
Root user without the proper authorisation.


Set root password? [Y/n] <-enter
New password: <-set a User password
Re-enter new password: <-enter your password again
Password updated successfully!
Reloading privilege tables ..
... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
To log into MySQL without having to have a user account created
Them. This is intended only for testing, and to make the installation
Go a bit smoother. You shoshould remove them before moving into
Production environment.


Remove anonymous users? [Y/n] <-enter
... Success!


Normally, root shoshould 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] <-enter
... Success!


By default, MySQL comes with a database named 'test' that anyone can
Access. This is also intended only for testing, and shocould be removed
Before moving into a production environment.


Remove test database and access to it? [Y/n] <-enter
-Dropping test database...
... Success!
-Removing privileges on test database...
... Success!


Reloading the privilege tables will ensure that all changes made so far
Will take effect immediately.


Reload privilege tables now? [Y/n] <-enter
... Success!


Cleaning up...


All done! If you 've completed all of the above steps, your MySQL
Installation shoshould now be secure.


Thanks for using MySQL!


[Root @ server1 ~] #




In linux, the root password of mysql is missing.


1. First confirm that the server is in a secure state, that is, no one can connect to the MySQL database at will.
Because, during the resetting of the MySQL root Password, the MySQL database is completely out of password-free
Other users can log on to and modify MySQL information as needed. You can use
The external port is closed, and Apache and all user processes are stopped to implement server quasi-security.
Status. The safest status is to operate on the server Console and unplug the network cable.
2. Modify MySQL Logon Settings:
# Vi/etc/my. cnf
In the [mysqld] section, add skip-grant-tables.
For example:
[Mysqld]
Datadir =/var/lib/mysql
Socket =/var/lib/mysql. sock
Skip-grant-tables
Save and exit vi.
3. Restart mysqld
#/Etc/init. d/mysqld restart
Stopping MySQL: [OK]
Starting MySQL: [OK]
4. log on to and modify the MySQL root Password
#/Usr/bin/mysql
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 3 to server version: 3.23.56
Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.
Mysql> USE mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with-
Database changed
Mysql> UPDATE user SET Password = password ('new-password') WHERE User = 'root ';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0
Mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
Mysql> quit
Bye
5. Modify the MySQL Logon Settings.
# Vi/etc/my. cnf
Delete the skip-grant-tables added to the [mysqld] section.
Save and exit vi.
6. Restart mysqld
#/Etc/init. d/mysqld restart
Stopping MySQL: [OK]

Starting MySQL: [OK]

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.