Install MySQL database in Linux initial environment

Note: The following commands can be copied (# . #)

  • 1. Prerequisites

[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl restart firewalld
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33

BOOTPROTO=static
IPADDR=192.168.2.1
NETMASK=255.255.255.0

[root@localhost ~]# systemctl restart network

  • Two, edit YUM source
[root@localhost ~]# vim /etc/yum.repos.d/qqq.repo
[suibian]
baseurl=file:///huaizhe
enabled=1
gpgcheck=0
  • Three, drag into the virtual machine software package

Insert picture description here

  • Fourth, mount the CD

[root@localhost ~]# mkdir /huaizhe
[root@localhost ~]# mount /dev/cdrom /huaizhe/
mount: /dev/sr0 is write-protected and will be mounted as read-only

  • Five, install MySQL dependent environment

[root@localhost ~]# yum -y install ncurses-devel

  • Six, install cmake tools

cmake is a compilation tool that replaces the function of the configure command when installing mysql, and is used to configure the installation options and operating environment of mysql.

[root@localhost ~]# tar -zxvf cmake-2.8.6.tar.gz -C /usr/src
[root@localhost ~]# cd /usr/src/cmake-2.8.6/
[[email protected]]# ./configure && gmake && gmake install

Note:
[1] Use gmake to compile and install the cmake tool
[2] Use cmake to configure the installation options of myslq
[3] Finally, use make to compile and install mysql.

  • Seven, install MySQL

[root@localhost cmake-2.8.6]# cd
[root@localhost ~]# tar -zxvf mysql-5.6.36.tar.gz -C /usr/src
[root@localhost ~]# cd /usr/src/ mysql-5.6.36/
[root@localhost mysql-5.6.36]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all
(note the space here One more or one less space will make an error)

Option description:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql #指定安装路径
-DSYSCONFDIR=/etc #Specify the configuration file path
-DDEFAULT_CHARSET=utf8
#Specify the character type -DDEFAULT_COLLATION=utf8_general_ci
#Specify the character set -DWITH_EXTRA_CHARSETS=all #Open the extended character set

[root@localhost mysql-5.6.36]# make && make install

  • 8. Path and service script optimization {Note: different packages mean different files in the support-files directory}

Optimize the mysql command path:

[root@localhost mysql-5.6.36]# ln /usr/local/mysql/bin/* /usr/local/bin/

Copy the mysql configuration file to the /etc directory:

cp /usr/src/mysql-5.6.36/support-files/my-default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y

Copy the mysql script file to the /etc/rc.d/init.d/ directory

 cp /usr/src/mysql-5.6.36/support-files/mysql.server /etc/rc.d/init.d/mysqld 
 chmod a+x /etc/rc.d/init.d/mysqld

Add the mysqld service to the service manager

 [root@localhost mysql-5.6.36]# chkconfig --add mysqld
 [root@localhost mysql-5.6.36]# chkconfig mysqld on
  • Nine, initialize mysql

Create mysql users and groups:

[root@localhost mysql-5.6.36]# groupadd mysql
[root@localhost mysql-5.6.36]# useradd -s /sbin/nologin -g mysql mysql

Install perl runtime components and runtime environment:

[root@localhost mysql-5.6.36]# yum -y install perl perl perl-devel perl-DBD* #install perl language environment

Initialize mysql:

/usr/local/mysql/scripts/mysql_install_db --user=mysql --group=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

Option description:
–user=mysql #Process management user
–group=mysql
#Process management group –basedir=/usr/local/mysql
#Specify mysql base directory –datadir=/usr/local/mysql/data #Specify mysql database storage directory

  • 10. Start the service and set the password of the root user
[root@localhost mysql-5.6.36]# systemctl restart mysqld

root用户第一次设置密码:
[root@localhost mysql-5.6.36]# mysqladmin -u root password
root用户修改密码:
[root@localhost mysql-5.6.36]]# mysqladmin -u root -p password
  • 11. The experiment was successful:

Log in to mysql: mysql -u root -p

Guess you like

Origin blog.csdn.net/qq_50573146/article/details/109824688