Introduction and installation of MySQL database

Introduction to MySQL

MySQL is an open source relational database management system (RDBMS) that uses the most commonly used database management language-Structured Query Language (SQL) for database management.

MySQL is open source, so anyone can download it under the General Public License and modify it according to individual needs.

MySQL has attracted much attention because of its speed, reliability and adaptability. Most people think that MySQL is the best choice for managing content without transactional processing.

The name of the MySQL dolphin logo is "sakila", which was selected by the founder of MySQL AB from a large list of names suggested by users in the "Dolphin Name" contest.

MySQL, although the function may not be very powerful, but because of its open source and wide spread, many people have learned about this database.

What is a MySQL database

MySQL is a popular Kaiyuan relational database

  • Oracle's products
  • Comply with the GPL agreement, free to use and modify
  • Features
    • Excellent performance and stable service
    • Open source, no copyright restrictions, low cost
    • Multi-threaded, multi-user
    • Give C/S (client/server) architecture
    • Safe and reliable

What is the difference between MySQL Business Edition and Community Edition

  • MySQL Business Edition is developed and maintained by MySQL AB, and requires payment to use
  • MySQL Community Edition is developed and maintained by MySQL developers and enthusiasts scattered all over the world, and can be used for free

The difference between the two

  • The commercial version has stricter organization management and testing, and will be more stable than the community version
  • The commercial version does not comply with the GPL, the community version is free to use in compliance with the GPL
  • The commercial version can get 7*24 hours of service, the community version does not

MySQL product camp

The first camp: the 5.0-5.1 camp, which can be said to be the continuation of the earlier products. The
second camp: the 5.4-5.7 camp, which integrates storage engines developed by MySQL AB, the community and third-party companies to improve performance. The
third camp: 6.0- The 7.1 camp is the MySQL Cluster version developed to meet the needs of the database cluster in the new era

MySQL compilation and installation

Prepare MySQL and boost compression package,
Insert picture description here
install the mysql environment, and prepare the dependent package environment

yum -y install gcc \
gcc-c++ \
ncurses \	#字符终端的包,方便终端操作
ncurses-devel \
bison \	#函数库
cmake	#没有configure,使用cmake

useradd -s /sbin/nologin mysql  #创建程序型用户

Compile and install

解压mysql-boost-5.7.20.tar.gz到opt目录下
进入mysql1-57.20目录

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \	#sock;通讯文件,连接数据库,通讯协议的载体
-DSYSCONFDIR=/etc \	#配置目录指向etc
-DSYSTEMD_PID_DIR=/usr/local/mysql \	#pid文件位置
-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位置
-DWITH_SYSTEMD=1	#守护进程

make & make install

Edit configuration file

cd /etc
vim my.cnf
#将内容全部删除,添加以下内容
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1

sql_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_QUOTES

Set environment variables

echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
source /etc/profile

Initialize the database

[root@localhost local]# cd /usr/local/mysql/
[root@localhost mysql]# bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data 
[root@localhost mysql]# cp usr/lib/systemd/system/mysqld.service /lib/systemd/system/
数据库开启
[root@localhost mysql]# systemctl start mysqld.service
[root@localhost mysql]# netstat -natp | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      41525/mysqld

Set a password to log in to the database

设置MySQL密码
[root@localhost mysql]# mysqladmin -u root -p password
#第一次没密码直接回车输入新密码
登录数据库查看
[root@localhost mysql]# mysql -u root -p

MySQL add users to allow remote access

grant all privileges on *.* to 创建的用户名 @"%" identified by "密码";

Guess you like

Origin blog.csdn.net/CN_PanHao/article/details/108049954