linux安装mysql

1 下载安装包
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
2 解压
tar -xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
3 移动到/usr/local下
mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
4 创建data目录
mkdir /usr/local/mysql/data
5 创建mysql用户
[查看有没有mysql组]# cat /etc/group | grep mysql
[查看有没有mysql用户]# cat /etc/passwd |grep mysql
没有就创建:
groupadd mysql
useradd -r -g mysql mysql
6 更改目录权限
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql
7 编译安装并初始化mysql,务必记住初始化输出日志末尾的密码(数据库管理员临时密码)
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
在这里插入图片描述
8 编辑/etc/my.cnf

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
symbolic-links=0
max_connections=5000
innodb_file_per_table=1
#表名大小写不明感,敏感为
#lower_case_table_names=1
socket=/tmp/mysql.sock
#socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

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

10 查询mysql mysqlid服务

#查询服务
ps -ef|grep mysql
ps -ef|grep mysqld

#结束进程
kill -9 PID

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

11 添加软连接
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

12 登陆mysql服务:
mysql -u root -p
Enter password:前面第7步生成的初始密码
mysql>set password for root@localhost = password(‘yourpass’);改密码

13 开放远程连接
mysql>use mysql;
msyql>update user set user.Host=’%’ where user.User=‘root’;
mysql>flush privileges;

14 设置开机自动启动
1、将服务文件拷贝到init.d下,并重命名为mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
2、赋予可执行权限
chmod +x /etc/init.d/mysqld
3、添加服务
chkconfig --add mysqld
4、显示服务列表
chkconfig --list

15 完成了呗,喀喀喀!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值