linux常用环境配置-MySQL

配置MySQL环境

01.下载

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
linux常用环境配置-MySQL_第1张图片
下载

02.解压

tar xzvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
解压

03.移动该文件到/usr/local/mysql, 在/usr/local/mysql目录下创建data目录

mv mysql-5.7.26-linux-glibc2.12-x86_64 /usr/local/mysql
mkdir /usr/local/mysql/data

04.创建mysql组和用户, 更改mysql目录下所有的目录及文件夹所属的用户组和用户,以及权限

groupadd mysql
useradd -r -g mysql mysql
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql

4、编译安装并初始化mysql,务必记住初始化输出日志末尾的密码(数据库管理员临时密码)

cd /usr/local/mysql/bin
 ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql

如果报错./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory则安装yum -y install numactl

安装成功

linux常用环境配置-MySQL_第2张图片
安装成功,注意密码

5.编辑配置文件my.cnf,添加配置如下

vi /etc/my.cnf

[mysqld]
datadir=/usr/local/mysql/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
#表名大小写不明感,敏感为
lower_case_table_names=1

#参考
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql-5.7.26
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0

  1. 启动mysql服务器
/usr/local/mysql/support-files/mysql.server start

如果出现如下提示信息
Starting MySQL... ERROR! The server quit without updating PID file
查看是否存在mysql和mysqld的服务,如果存在,则结束进程,再重新执行启动命令

ps -ef|grep mysql
ps -ef|grep mysqld

#结束进程
kill -9 PID

#启动服务
 /usr/local/mysql/support-files/mysql.server start

添加软连接,并重启mysql服务

ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql 
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
service mysql restart
  1. 登录mysql,修改密码(密码为步骤5生成的临时密码)
mysql -u root -p
Enter password:
mysql>set password for root@localhost = password('yourpass');
  1. 开放远程连接
mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;
  1. 设置开机自动启动
1、将服务文件拷贝到init.d下,并重命名为mysqld
[root@localhost /]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
2、赋予可执行权限
[root@localhost /]# chmod +x /etc/init.d/mysqld
3、添加服务
[root@localhost /]# chkconfig --add mysqld
4、显示服务列表
[root@localhost /]# chkconfig --list

参考:linux下安装MySQL

你可能感兴趣的:(linux常用环境配置-MySQL)