Overview and installation of MySQL database

1. Introduction to MySQL database

  • MySQL is a relational database management system . Relational databases store data in different tables instead of putting all data in one large database, which increases speed and flexibility
  • The SQL language used by MySQL is the most commonly used standardized language for accessing databases(包括 SQL server和Oracle都有自己专门的SQL语言,但是格式都是差不多的,因为都是关系型数据库,都有着固定的格式 库——表——数据)
  • MySQL software adopts a dual authorization policy, divided into community version and commercial version. Due to its small size, fast speed, and low overall cost of ownership, especially the feature of open source (也就是开源软件,完全免费的软件), the development of general small and medium-sized websites chooses MySQL as the website. database(后期如果需要扩大,可以配合redis数据库和Mysql结合)
  • MySQL definition: is a true multi-threaded, multi-user SQL database service, with high performance, high reliability, and easy-to-use features
  • The default port number used is: tcp 3306

Two, install Mysql-5.6.36 version

  • Advantages of compiling and installing mysql database: to ensure the integrity and customization of functions(因为源代码编译安装是可以指定添加的功能的)
  • step:

(1) Preparation

  • In order to avoid port conflicts, program conflicts, etc., first make sure that the machine does not use rpm to install the mysql-server and mysql software packages
[root@mysql ~]#rpm  -q  mysql-server  mysql

Confirm that it is not installed

  • Use yum to install the ncurses-devel plugin package. If there is no local yum source, you can write a local yum source first
  • Mount the disc image
[root@mysql ~]#mount  /dev/cdrom  /media/cdrom
[root@mysql ~]#yum  -y   install   ncurses-devel

Mount
Install plugin package

  • Local yum source
    Local yum source
  • MySQL 5 version needs to use cmake to compile, so you have to upload the package cmake, and then decompress, configure and install(过程需要五六分钟)
[root@mysql~]#tar zxvf cmake-2.8.6.tar.gz 
[root@mysql cmake- 2.8.6]#cd cmake-2.8.6/       
[root@mysql cmake- 2.8.6]#./configure         
[root@mysql cmake- 2.8.6]#gmake  && gmake  install

Upload cmake
Install and configure cmake
So far, all preparations are completed

(2) Source code compilation and installation

  • Create running users and groups to strengthen the authority control of database services
[root@mysql ~]#groupadd mysql   
[root@mysql ~]#useradd -M -s /sbin/nologin mysql -g mysql   

Create users and groups
Create a mysql user and join the created mysql group, -M does not create a sink group directory, -s specifies that the shell /sbin/nologin is not allowed to log in to the system

  • Upload the package, unpack, (可以使用xshell上传)configure, and install.
[root@mysql ~]#tar zxvf mysql-5.6.36.tar.gz -C /usr/src   
[root@mysql mysql-5.6.36]#cd /usr/src/mysql-5.6.36/     

Unzip

  • There are a lot of mysql functions configured, just copy the following, remember to switch to the directory where the MySQL software package was decompressed for configuration and installation
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  -DSYSCONFDIR=/etc  -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci  -DWITH_EXTRA_CHARSETS=all 
配置的mysql的功能的作用:
-DCMAKE_INSTALL_PREFIX :指定安装位置 
-DSYSCONFDIR: 初始化参数文件的位置
-DDEFAULT_CHARSET:  默认的字符集编码
-DDEFAULT_COLLATION: 默认使用的字符集校对规则
-DWITH_EXTRA_CHARSETS:额外安装的其他字符集 

It can be written like this, and it will be installed automatically after the configuration is complete(看自己的电脑性能,好点的二十分钟,配置差点的估计得四十分钟)

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  -DSYSCONFDIR=/etc  -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci  -DWITH_EXTRA_CHARSETS=all && make && make install

Configuration installation

  • The installation is complete
    The installation is complete
  • After installation, you have to make some adjustments to the database directory permissions and the main configuration file.
    Recursively change the owner and group users of the mysql home directory to mysql, delete the default configuration file, and make a copy in the home directory.
[root@mysql ~]#chown -R mysql:mysql /usr/local/mysql/
[root@mysql ~]#rm -rf /etc/my.cnf
[root@mysql ~]#cd /usr/local/mysql
[root@mysql mysql]#cp support-files/my-default.cnf /etc/my.cnf 

Adjustment

  • Initialize the database system(以用户mysql的身份执行初始化脚本)
/usr/local/mysql/scripts/mysql_install_db  --user=mysql  --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ 

Initialize the database system

  • Set environment variables(方便在任何目录下都能使用mysql命令)
[root@mysql mysql]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@mysql mysql]#. /etc/profile 

Set environment variables
./etc/profile is effective immediately

  • Add as system service(方便通过systemctl系统命令进行管理)
[root@mysql ~]#cp support-files/mysql.server /usr/local/mysql/bin/mysqld.sh   
`(复制服务脚本并重命名为mysqld.sh)`
[root@mysql ~]#chmod +x /usr/local/mysql/bin/mysqld.sh  
` (添加可执行权限)`

Add as system service

  • Create a configuration file for mysql system service
[root@mysql mysql]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=Mysql Server
After=network.target
[Service]
User=mysql
Group=mysql
Type=forking
PIDFILE=/usr/local/mysql/data/www.pid
ExecStart=/usr/local/mysql/bin/mysqld.sh start
ExecStop=/usr/local/mysql/bin/mysqld.sh stop
[Install]
WantedBy=multi-user.target
`保存退出`

Insert picture description here

  • At this time, it can be managed by system commands. You can check the port number and find that it has been started up to
    Direct management of system commands
    View port number
    this point. The installation of mysql has been completed. When installing and configuring, you should be in the decompression directory of mysql.

Guess you like

Origin blog.csdn.net/rzy1248873545/article/details/110468209