The main objective of this experiment is to build mysql server
First, the preparatory work
1, to prepare a host of rhel7.2
2, download the rpm package: wget https://dev.mysql.com/downloads/mysql/mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar
3, unloading system comes with a database of mariadb
查找:rpm -qa | grep mariadb-server
如果有的话就卸载:yum -y remove mariadb-server mariadb
并删除清理/etc/my.cnf配置文件
Second, the installation
1, extract: tar -xf mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar
2, delete the rpm package minimal installation:
rm -rf mysql-community-server-minimal-5.7.17-1.el7.x86_64.rpm
3, the installation dependencies:
yum -y install perl-Data-Dumper perl-JSON perl-Time-HiRes
4, install the database, -U is an upgrade installation
rpm -Uvh mysql-community-*.rpm
5, restart the service, the service boot from the start
systemctl restart mysqld; systemctl enable mysqld;
6, view and validate
Check whether to activate: ps -aux | grep 3306 netstat -ntulp | grep 3306
The data files: / var / lib / mysql
Wide configuration files path: /etc/my.cnf
Initial log Path: /var/log/mysqld.log
Third, the initial password change process
由于mysql5.7rpm安装过程中,会产生一个原始的密码,必须修改后才能使用
Here's the password so that the editing process:
1, modify the configuration file:
validate_password_policy=0 //0是取消密码复杂度,默认为1
validate_password_length=6 //最少密码长度为6
2, restart the database service: systemctl restart mysqld
3, see the original password:
grep 'temporary password' /var/log/mysqld.log
得到:root@localhost: l)VFhq1zSto>
4, with the original password: mysql -uroot -p'l) VFhq1zSto> '
-u指定用户,-p指定密码
5, to modify the original code: set password = password ( "123456");
6, exit, and then use the new password to verify the change of landing.
Fourth, some of the basic operation of the database:
1, the library-related operations:
select database(); //确认当前所在的库
create database bbsdb; //创建数据库
use mysql; //切换数据库
drop database bbsdb; //删除库
2, some of the basic operations related table:
create table stuinfo (name char (10), sex char (5), class char (8)); // Create a table
insert into stuinfo values ( "tom", "boy", "123"); // data inserted into the table
update stuinfo set name = "hehe" where sex = "reny"; // update the data table
desc stuinfo; // View table structure
delete from stuinfo; // delete all the contents of the table
drop table stuinfo; // Delete table
3, the operation of the modified table structure:
Adding fields: alter table table Field Name Type add constraints first after (field name);
Delete field: alter table table name drop field names;
Review Field Type: alter table modify table Field Name Type constraints;
Changes to field names: alter table change table name field name New Source Field Name Type constraints;
Modify table: alter table source table name rename the new table name;