Install mysql under centos6.5
1. Use the yum command to install mysql
[Html] view plaincopy
- [Root @ bogon ~] # Yum-yinstallmysql-server
2. Set startup
[Html] view plaincopy
- [Root @ bogon ~] # Chkconfigmysqldon
3. Start the MySQL Service
[Html] view plaincopy
- [Root @ bogon ~] # Servicemysqldstart
4. Set the password for the root user of MySQL
[Html] view plaincopy
- [Root @ bogon ~] # Mysql-uroot
- Mysql> selectuser, host, passwordfrommysql. user;
- + ------ + ----------- + ---------- +
- | User | host | password |
- + ------ + ----------- + ---------- +
- | Root | localhost |
- | Root | bogon |
- | Root | 127.0.0.1 |
- | Localhost |
- | Bogon |
- + ------ + ----------- + ---------- +
- 5 rowsinset (0.01sec)
The query password is empty. Use the following command to set the root password to root.
[Html] view plaincopy
- Mysql> setpasswordforroot @ localhost = password ('root ');
- Mysql> exit
5. log in with the new password
[Html] view plaincopy
- [Root @ bogon ~] # Mysql-uroot-p
- Enterpassword:
6. Create a New mysql user test_user
[Html] view plaincopy
- Mysql> createuser 'test _ user' @ '%' identifiedby 'test _ user ';
- 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
- Mysql> grantallprivilegeson *. * to 'test _ user' @ 'localhost' identifiedby 'test _ user ';
- QueryOK, 0 rowsaffected (0.00sec)
- Mysql> grantallprivilegeson *. * to 'test _ user' @ '%' identifiedby 'test _ user ';
- QueryOK, 0 rowsaffected (0.00sec)
- Mysql> selectuser, host, passwordfrommysql. user;
- + ---------- + ----------- + --------------------------------------------- +
- | User | host | password |
- + ---------- + ----------- + --------------------------------------------- +
- | Root | localhost | * 81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
- | Root | bogon |
- | Root | 127.0.0.1 |
- | Localhost |
- | Bogon |
- | Test_user | % | * 3046CF87132BBD4FDDF06F321C6859074843B7D3 |
- | Test_user | localhost | * 3046CF87132BBD4FDDF06F321C6859074843B7D3 |
- + ---------- + ----------- + --------------------------------------------- +
- 7 rowsinset (0.00sec)
- Mysql> flushprivileges;
- 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
- Mysql> showengines;
- + ------------ + --------- + ---------------------------------------------------------- + -------------- + ------ + ------------ +
- | Engine | Support | Comment | Transactions | XA | Savepoints |
- + ------------ + --------- + ---------------------------------------------------------- + -------------- + ------ + ------------ +
- | MRG_MYISAM | YES | CollectionofidenticalMyISAMtables | NO |
- | CSV | YES | CSVstorageengine | NO |
- | MyISAM | DEFAULT | DefaultengineasofMySQL3.23withgreatperformance | NO |
- | InnoDB | YES | Supportstransactions, row-levellocking, andforeignkeys | YES |
- | MEMORY | YES | Hashbased, storedinmemory, usefulfortemporarytables | NO |
- + ------------ + --------- + ---------------------------------------------------------- + -------------- + ------ + ------------ +
- 5 rowsinset (0.00sec)
You can also view
[Html] view plaincopy
- Mysql> showvariableslike 'Storage _ engine ';
- + ---------------- + -------- +
- | Variable_name | Value |
- + ---------------- + -------- +
- | Storage_engine | MyISAM |
- + ---------------- + -------- +
- 1 rowinset (0.00sec)
9. Modify the default mysql engine to InnoDB.
9.1 stop mysql
[Html] view plaincopy
- Mysql> exit;
- [Root @ bogon ~] # Servicemysqldstop
9.2 Modify/etc/my. cnf
[Mysqld] Later
[Html] view plaincopy
- Default-storage-engine = InnoDB
The content of my. cnf is:
[Html] view plaincopy
- [Root @ bogonetc] # moremy. cnf
- [Mysqld]
- Datadir =/var/lib/mysql
- Socket =/var/lib/mysql. sock
- User = mysql
- # Disablingsymbolic-linksisrecommendedtopreventassortedsecurityrisks
- Symbolic-links = 0
- Default-storage-engine = InnoDB
- [Mysqld_safe]
- Log-error =/var/log/mysqld. log
- Pid-file =/var/run/mysqld. pid
9.3 start mysql
[Html] view plaincopy
- [Root @ bogonetc] # servicemysqldstart
- Startingmysqld: [OK]
9.4 view the default storage engine of mysql
[Html] view plaincopy
- [Root @ bogonetc] # mysql-uroot-p
- Enterpassword:
- WelcometotheMySQLmonitor. Commandsendwith; or \ g.
- YourMySQLconnectionidis2
- Serverversion: 5.1.73Sourcedistribution
- Copyright (c) 2000,2013, Oracleand/oritsaffiliates. Allrightsreserved.
- Oracleisaregisteredtrademarkoforacleconfigurationand/orits
- Affiliates. Othernamesmaybetrademarksoftheirrespective
- Owners.
- Type 'help; 'or' \ H' forhelp. Type '\ C' toclearthur ecurrentinputstatement.
- Mysql> showvariableslike 'Storage _ engine ';
- + ---------------- + -------- +
- | Variable_name | Value |
- + ---------------- + -------- +
- | Storage_engine | InnoDB |
- + ---------------- + -------- +
- 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
- -AINPUT-mstate -- stateNEW-mtcp-ptcp -- dport3306-jACCEPT
After modification, the content in iptables is
[Html] view plaincopy
- [Root @ bogonetc] # more/etc/sysconfig/iptables
- # Firewallconfigurationwrittenbysystem-config-firewall
- # Manualcustomizationofthisfileisnotrecommended.
- * Filter
- : INPUTACCEPT [0: 0]
- : FORWARDACCEPT [0: 0]
- : OUTPUTACCEPT [0: 0]
- -AINPUT-mstate -- stateESTABLISHED, RELATED-jACCEPT
- -AINPUT-picmp-jACCEPT
- -AINPUT-ilo-jACCEPT
- -AINPUT-mstate -- stateNEW-mtcp-ptcp -- dport22-jACCEPT
- # Add configuration items
- -AINPUT-mstate -- stateNEW-mtcp-ptcp -- dport80-jACCEPT
- -AINPUT-mstate -- stateNEW-mtcp-ptcp -- dport11211-jACCEPT
- -AINPUT-mstate -- stateNEW-mtcp-ptcp -- dport3306-jACCEPT
- -AINPUT-jREJECT -- reject-withicmp-host-prohibited
- -AFORWARD-jREJECT -- reject-withicmp-host-prohibited
- COMMIT
11. Restart the Firewall
[Html] view plaincopy
- [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.