搭建LNMP架构 ---- Mysql配置
一:Mysql 概述
MySQL是一种关系数据库管理系统,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性 。
二:配置过程
1、安装需要的环境软件包
[root@localhost ~]# yum install ncurses ncurses-devel bison cmake -y
2、创建运行用户 mysql ,并解压mysql 的压缩包
[root@localhost system]# useradd -s /sbin/nologin mysql
cd /abc '创建运行用户'
[root@localhost abc]# tar zxvf mysql-boost-5.7.20.tar.gz -C /opt/
3、在mysql-5.7.20 目录中编译cmake
[root@localhost abc]# cd /opt/mysql-5.7.20/
[root@localhost mysql-5.7.20]#
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ ‘安装路径’
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ ‘通讯文件’
-DSYSCONFDIR=/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=boost \
-DWITH_SYSTEMD=1
[root@localhost mysql-5.7.20]# make && make install
[root@localhost mysql-5.7.20]# chown -R mysql.mysql /usr/local/mysql ‘设置权限’
4、在/etc目录下, vim my.cnf 调整配置文件 (删除原有内容)
[root@localhost mysql-5.7.20]# cd /etc/
[root@localhost 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/mysql.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
5、设置环境变量,并生效
[root@localhost etc]# chown mysql.mysql /etc/my.cnf
[root@localhost etc]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
[root@localhost etc]# echo 'export PATH' >> /etc/profile
[root@localhost etc]# source /etc/profile ‘让/etc/profile修改的文件命令生效’
[root@localhost etc]# cd /usr/local/mysql
[root@localhost mysql]# ls
[root@localhost mysql]# ls bin/
mysqld
...省略内容
6、初始化数据库
[root@localhost mysql]# bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
7、 保持路径不变,将服务复制到 /lib/systemd/system/路径下,可以用systemctl控制管理
[root@localhost mysql]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
[root@localhost mysql]# systemctl start mysqld ‘开启mysql服务’
[root@localhost mysql]# netstat -ntap | grep mysqld ‘查看端口是否正常开启’
tcp6 0 0 :::3306 :::* LISTEN 26928/mysqld
[root@localhost mysql]# systemctl enable mysqld ‘开机自启’
8、登录数据库,设置mysql数据库的密码 (密码默认是没有的,直接回车即可)
7、登录数据库,设置数据库的密码
[root@localhost mysql]# mysql -u root -p
‘‘一直按回车键’’
[root@localhost mysql]# mysqladmin -uroot -p password
Enter password: "按回车"
New password: “输入新的密码”
Confirm new password: “再次输入密码”
[root@localhost mysql]# mysql -u root -p ‘登录数据库’
Enter password: ‘输入刚新设置的密码’
Mysql服务已配置完成。
来源:CSDN
作者:Sunny~~~
链接:https://blog.csdn.net/XuMin6/article/details/103671453