A, MySQL Introduction
- MySQL is a relational database management system, is developed by MySQL AB, now part of Oracle's products.
MySQL use of standardized languages. Small size, high speed, low cost, open source and so makes some small and medium sized sites are choosing to use MySQL as the database website.
Two, MySQL installation
1. Installation Environment
- System: CentOS 6.8 64 Wei
- MySQL: mysql-server-5.1.73 Community Edition
-
Installation procedure
1) the installation instructions
yum -y install mysql-server
Note: Whether to use sudo privileges to perform, depending on your specific environment decide
2) Run, mysql-server checks whether to install
rpm -qa|grep mysql-server
Three, MySQL configuration
- Note: The default configuration file /etc/my.cnf
Note: Whether to use sudo privileges to perform, depending on your specific environment decide
1. Character set configuration
- About Chinese garbage problem in version 5.1, to solve the Chinese garbled, within my.ini [mysql] and [mysqld] are added
default-character-set = utf8
- It can be written in the 5.5 version, [mysql] inside, so can not write [mysqld] inside, but added
character-set-server=utf8
1) Modify my.cnf configuration:
sudo vim /etc/my.conf
2) adding configure added at [mysqld] node:
default-character-set = utf8
character-set-server = utf8
3) Save and exit
By vim's ": wq" command to save and exit. If it is in edit mode, need to press the Esc key, and then enter the command.
2. Since the launch configuration
1) First Run
chkconfig mysqld on
2) then execute mysql view state, if the state is on 2-5 start bit can be.
chkconfig --list mysqld
3. Firewall Configuration
1) Edit Firewall Configuration
sudo vim /etc/sysconfig/iptables
2) Add a rule (open port 3306)
-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
3) Save and exit
By vim's ": wq" command to save and exit. If it is in edit mode, need to press the Esc key, and then enter the command.
4) Restart the firewall
sudo service iptables restart
4. Start MySQL
sudo service mysqld start
or
/etc/rc.d/init.d/mysqld start
5. MySQL environment configuration
Because mysql has not yet set a password, you need to set a password to log database server.
- set password
mysql -u root
- After logging in as follows:
- View all users
select user,host from mysql.user;
- Delete anonymous users:
delete from mysql.user where user='';
- View all users
select user,host from mysql.user;
- Insert a user
insert into mysql.user(Host, User, Password) values("localhost", "huaiangg", Password("123456"));
- View user database has been added
- Creating a database
create database `mmall` default character set utf8 collate utf8_general_ci;
- View database permissions (\ G format):
select * from mysql.user \G;
- Gives full access (because of the need to connect remotely, open to all ip can be connected '%')
-- on 后面接的是 数据库名.表名 .*表示该数据库下的所有表
-- root@localhost 表示用户名@ip地址
-- identitified by '123456' ''里面表示该账户的密码
-- with grant option 表示可以把自己的权限赋值给别的用户
grant all privileges on mmall.* to root@'%' identified by '123456' with grant option;
- Change password
-- root@localhost ->> 用户名@ip
-- Password() ->> 内置函数
set password for root@localhost=Password('123456');
- User password, type the following command, and then enter a password to login.
mysql -u root -p
4, MySQL of verification
1. Check the running mysql server ip address
ifconfig
2. The tool is connected via client (herein Navicat)
- Navicat + cracking tools - CSDN download link
Hand party can contact the author directly Get the download link.
3. The installation process is not explained, are interested can look at the article, where directly attached to the test connection diagram:
Mysql 8.0 Installation & Navicat for MySQL Tutorial
1) is connected to the database centos
2) then the connection has been successfully completed installation
Five, MySQL commonly used commands
1. Review the current mysql user
select user,host,password from mysql.user;
2. Change the root password (using the built-in function to modify)
set password for root@localhost=password('your new password');
or
set password for [email protected]=password('your new password');
3. Exit mysql
exit
4. Re-login (password is required)
mysql -u root -p
5. Delete anonymous users
- To see if there are anonymous users
select user,host from mysql.user;
- Remove the anonymous user (user = '', '' represents an empty string)
delect from mysql.user where user = '';
- Refresh, make the operation to take effect
flush privileges;
6. Add a new user mysql
insert into mysql.user(Host,User,Password) values("localhost", "yourusername", password("yourpaddword"));
- Refresh, make the operation to take effect
flush privileges;
7. Create a new database
CREATE DATABASE `db_test` DEFAULT CHARRACTER SET utf8 COLLATE utf8_general_ci;
8. All rights given to local users
grant all privileges on db_test.* to yourusername@localhost identified by 'yourpassword';
9. give an account opened outside the network all permissions
grant all privileges on db_test.* to 'yourusername'@'%' identified by 'yourpassword';
- It should be administered under the authority they need permission, such as all the additions and changes to the database tables under db_test investigation authority (not to delete rights) to the host to 192.168.199.111, worded as follows:
grant select,insert,update on db_test.* to yourusername@'192.168.199.111' identified by 'yourpassword';
If a man unknown to concentrate fall asleep!
Like a friend you can leave your praise!