Install mysql under centos6.5

Source: Internet
Author: User

Install mysql under centos6.5

1. Use the yum command to install mysql

[Html] view plaincopy
  1. [Root @ bogon ~] # Yum-yinstallmysql-server

2. Set startup

[Html] view plaincopy
  1. [Root @ bogon ~] # Chkconfigmysqldon

3. Start the MySQL Service

[Html] view plaincopy
  1. [Root @ bogon ~] # Servicemysqldstart

4. Set the password for the root user of MySQL

[Html] view plaincopy
  1. [Root @ bogon ~] # Mysql-uroot
  2. Mysql> selectuser, host, passwordfrommysql. user;
  3. + ------ + ----------- + ---------- +
  4. | User | host | password |
  5. + ------ + ----------- + ---------- +
  6. | Root | localhost |
  7. | Root | bogon |
  8. | Root | 127.0.0.1 |
  9. | Localhost |
  10. | Bogon |
  11. + ------ + ----------- + ---------- +
  12. 5 rowsinset (0.01sec)

The query password is empty. Use the following command to set the root password to root.

[Html] view plaincopy
  1. Mysql> setpasswordforroot @ localhost = password ('root ');
  2. Mysql> exit

5. log in with the new password

[Html] view plaincopy
  1. [Root @ bogon ~] # Mysql-uroot-p
  2. Enterpassword:

6. Create a New mysql user test_user

[Html] view plaincopy
  1. Mysql> createuser 'test _ user' @ '%' identifiedby 'test _ user ';
  2. QueryOK, 0 rowsaffected (0.00sec)

7. Authorize the new user test_user to log on from outside and locally.
Note: "@" indicates the user name on the left, and "Domain Name", "IP address", and "%" indicate that the mysql domain name and IP address can be accessed. "%" indicates that all external addresses can be accessed.

[Html] view plaincopy
  1. Mysql> grantallprivilegeson *. * to 'test _ user' @ 'localhost' identifiedby 'test _ user ';
  2. QueryOK, 0 rowsaffected (0.00sec)
  3. Mysql> grantallprivilegeson *. * to 'test _ user' @ '%' identifiedby 'test _ user ';
  4. QueryOK, 0 rowsaffected (0.00sec)
  5. Mysql> selectuser, host, passwordfrommysql. user;
  6. + ---------- + ----------- + --------------------------------------------- +
  7. | User | host | password |
  8. + ---------- + ----------- + --------------------------------------------- +
  9. | Root | localhost | * 81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
  10. | Root | bogon |
  11. | Root | 127.0.0.1 |
  12. | Localhost |
  13. | Bogon |
  14. | Test_user | % | * 3046CF87132BBD4FDDF06F321C6859074843B7D3 |
  15. | Test_user | localhost | * 3046CF87132BBD4FDDF06F321C6859074843B7D3 |
  16. + ---------- + ----------- + --------------------------------------------- +
  17. 7 rowsinset (0.00sec)
  18. Mysql> flushprivileges;
  19. QueryOK, 0 rowsaffected (0.01sec)

8. view the default storage engine of mysql5.1
The following execution results show that the default mysql engine is MyISAM, which does not support transactions.

[Html] view plaincopy
  1. Mysql> showengines;
  2. + ------------ + --------- + ---------------------------------------------------------- + -------------- + ------ + ------------ +
  3. | Engine | Support | Comment | Transactions | XA | Savepoints |
  4. + ------------ + --------- + ---------------------------------------------------------- + -------------- + ------ + ------------ +
  5. | MRG_MYISAM | YES | CollectionofidenticalMyISAMtables | NO |
  6. | CSV | YES | CSVstorageengine | NO |
  7. | MyISAM | DEFAULT | DefaultengineasofMySQL3.23withgreatperformance | NO |
  8. | InnoDB | YES | Supportstransactions, row-levellocking, andforeignkeys | YES |
  9. | MEMORY | YES | Hashbased, storedinmemory, usefulfortemporarytables | NO |
  10. + ------------ + --------- + ---------------------------------------------------------- + -------------- + ------ + ------------ +
  11. 5 rowsinset (0.00sec)

You can also view

[Html] view plaincopy
  1. Mysql> showvariableslike 'Storage _ engine ';
  2. + ---------------- + -------- +
  3. | Variable_name | Value |
  4. + ---------------- + -------- +
  5. | Storage_engine | MyISAM |
  6. + ---------------- + -------- +
  7. 1 rowinset (0.00sec)

9. Modify the default mysql engine to InnoDB.
9.1 stop mysql

[Html] view plaincopy
  1. Mysql> exit;
  2. [Root @ bogon ~] # Servicemysqldstop

9.2 Modify/etc/my. cnf
[Mysqld] Later

[Html] view plaincopy
  1. Default-storage-engine = InnoDB

The content of my. cnf is:

[Html] view plaincopy
  1. [Root @ bogonetc] # moremy. cnf
  2. [Mysqld]
  3. Datadir =/var/lib/mysql
  4. Socket =/var/lib/mysql. sock
  5. User = mysql
  6. # Disablingsymbolic-linksisrecommendedtopreventassortedsecurityrisks
  7. Symbolic-links = 0
  8. Default-storage-engine = InnoDB
  9. [Mysqld_safe]
  10. Log-error =/var/log/mysqld. log
  11. Pid-file =/var/run/mysqld. pid

9.3 start mysql

[Html] view plaincopy
  1. [Root @ bogonetc] # servicemysqldstart
  2. Startingmysqld: [OK]

9.4 view the default storage engine of mysql

[Html] view plaincopy
  1. [Root @ bogonetc] # mysql-uroot-p
  2. Enterpassword:
  3. WelcometotheMySQLmonitor. Commandsendwith; or \ g.
  4. YourMySQLconnectionidis2
  5. Serverversion: 5.1.73Sourcedistribution
  6. Copyright (c) 2000,2013, Oracleand/oritsaffiliates. Allrightsreserved.
  7. Oracleisaregisteredtrademarkoforacleconfigurationand/orits
  8. Affiliates. Othernamesmaybetrademarksoftheirrespective
  9. Owners.
  10. Type 'help; 'or' \ H' forhelp. Type '\ C' toclearthur ecurrentinputstatement.
  11. Mysql> showvariableslike 'Storage _ engine ';
  12. + ---------------- + -------- +
  13. | Variable_name | Value |
  14. + ---------------- + -------- +
  15. | Storage_engine | InnoDB |
  16. + ---------------- + -------- +
  17. 1 rowinset (0.00sec)

10. Enable mysql port 3306 on CentOS6.5
CentOS6.5 is disabled by default. To allow external systems to access mysql on CentOS6.5, port 3306 of mysql must be enabled.
10.1 Modify/etc/sysconfig/iptables
Add the following line

[Html] view plaincopy
  1. -AINPUT-mstate -- stateNEW-mtcp-ptcp -- dport3306-jACCEPT

After modification, the content in iptables is

[Html] view plaincopy
  1. [Root @ bogonetc] # more/etc/sysconfig/iptables
  2. # Firewallconfigurationwrittenbysystem-config-firewall
  3. # Manualcustomizationofthisfileisnotrecommended.
  4. * Filter
  5. : INPUTACCEPT [0: 0]
  6. : FORWARDACCEPT [0: 0]
  7. : OUTPUTACCEPT [0: 0]
  8. -AINPUT-mstate -- stateESTABLISHED, RELATED-jACCEPT
  9. -AINPUT-picmp-jACCEPT
  10. -AINPUT-ilo-jACCEPT
  11. -AINPUT-mstate -- stateNEW-mtcp-ptcp -- dport22-jACCEPT
  12. # Add configuration items
  13. -AINPUT-mstate -- stateNEW-mtcp-ptcp -- dport80-jACCEPT
  14. -AINPUT-mstate -- stateNEW-mtcp-ptcp -- dport11211-jACCEPT
  15. -AINPUT-mstate -- stateNEW-mtcp-ptcp -- dport3306-jACCEPT
  16. -AINPUT-jREJECT -- reject-withicmp-host-prohibited
  17. -AFORWARD-jREJECT -- reject-withicmp-host-prohibited
  18. COMMIT

11. Restart the Firewall

[Html] view plaincopy
  1. [Root @ bogonetc] # serviceiptablesrestart

In this way, you can access mysql from the outside.

So far, the installation process, user creation, and external access steps of mysql on CentOS6.5 have been completed.

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.