Database necessity: The use of databases enables efficient and well-defined storage of data, enabling people to manage data more quickly and easily. The 3 characteristics of a database:
- Can be structured to store a large amount of data information, convenient for users to effectively search and access.
- Can effectively maintain the consistency of data information, integrity, reduce data redundancy.
- Can meet the sharing and security requirements of the application.
Experimental environment
- CENTOS7 system
- IP address 192.168.92.128
- Required Packages
Experimental deployment
1. Install the Environment pack
yum install gcc gcc-c++ ncurses ncurses-devel bison cmake make -y
2.mysql5.7 need boost library during installation, unzip and install the 2 compressed packages I provided at the beginning mysql-5.7.17.tar.gz and boost_1_59_0.tar.gz
tar zxvf mysql-5.7.17.tar.gz -C /opt/tar zxvf boost_1_59_0.tar.gz -C /usr/local/cd /usr/local/mv boost_1_59_0 boost
3. Create a MySQL user
useradd -M -s /sbin/nologin mysql #创建用户mysql,不创建家目录,不允许登陆系统
4. Configuration files
cd /opt/mysql-5.7.17 #进入该目录下cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #指定mysql安装目录-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ #连接文件位置-DSYSCONFDIR=/etc \ #指定配置文件目录 -DSYSTEMD_PID_DIR=/usr/local/mysql \ #进程文件目录-DDEFAULT_CHARSET=utf8 \ #指定默认使用的字符集编码-DDEFAULT_COLLATION=utf8_general_ci \ #指定默认使用的字符集校对规则-DWITH_INNOBASE_STORAGE_ENGINE=1 \ #存储引擎-DWITH_ARCHIVE_STORAGE_ENGINE=1 \ #存储引擎-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ #存储引擎-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ #存储引擎-DMYSQL_DATADIR=/usr/local/mysql/data \ #数据库文件-DWITH_BOOST=/usr/local/boost \ #指定boost库的位置,mysql5.7必须添加该参数-DWITH_SYSTEMD=1 #使系统支持mysql数据库
Note: If there is an error in the process of CMake, when the error is resolved, it is necessary to remove the CMakeCache.txt file from the source directory and then CMake again, otherwise the errors will remain
5. Compiling the installation takes a long time, if the virtual machine does the experiment can turn the processor higher.
make && make install
6. Modify the owner group of the database.
chown -R mysql:mysql /usr/local/mysql/
7. Modify the configuration file to add the following files
vim /etc/my.cnf[client]port = 3306default-character-set=utf8socket = /usr/local/mysql/mysql.sock[mysql]port = 3306default-character-set=utf8socket = /usr/local/mysql/mysql.sock[mysqld]user = mysqlbasedir = /usr/local/mysqldatadir = /usr/local/mysql/dataport = 3306character_set_server=utf8pid-file = /usr/local/mysql/mysqld.pidsocket = /usr/local/mysql/mysql.sockserver-id = 1sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTESchown mysql:mysql /etc/my.cnf
8. Modify the permissions of the configuration file
chown mysql:mysql /etc/my.cnf
9. Setting Environment variables
echo ‘PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH‘ >> /etc/profileecho ‘export PATH‘ >> /etc/profilesource /etc/profile #使写入生效
10. Initializing the database
cd /usr/local/mysql/bin/mysqld --initialize-insecure \ #生成初始化密码(mysql5.7),实际上生成空密码--user=mysql \ #指定管理用户--basedir=/usr/local/mysql \ #指定工作目录--datadir=/usr/local/mysql/data #指定数据库文件目录
11. Adding System Services
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ systemctl daemon-reload #重启daemon服务systemctl start mysqld #启动mysql服务netstat -anpt | grep 3306 #查看端口systemctl enable mysqld #开机自启动
12. Modify the database password
mysqladmin -u root -p password "abc123" #-u指定root账号设置密码为abc123
Log in to MySQL database
13. Login with Password
mysql -u root -p输入密码abc123
Your MySQL database is now installed.
14. If you want to log in remotely,
grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘abc123‘ with grant option; #/第一个“*”代表所有数据库,第二“*”代表所有表,赋予root权限 “%”代表所有服务器终端,可设为IP地址 密码为“abc123”
15. Turn off the firewall
systemctl stop firewalld.servicesetenforce 0
At this point you can log in remotely (Navicat terminal software) MySQL database
Centos7 Edit install MySQL (mysql-5.7)