linux安装mysql教程

1、系统约定

安装文件下载目录:/data/software
Mysql目录安装位置:/usr/local/mysql
数据库保存位置:/data/mysql
日志保存位置:/data/log/mysql

2、下载mysql

执行如下命令

mkdir /data/software
cd /data/software

–下载安装包

wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

3、解压压缩包到目标位置

tar -xzvf /data/software/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

–解压压缩包

tar -xzvf /data/software/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

–移动并修改文件名

mv /data/software/mysql-5.7.17-linux-glibc2.5-x86_64 /usr/local/mysql

4、创建数据仓库目录

–/data/mysql 数据仓库目录

mkdir /data/mysql
ls /data/在这里插入图片描述

5、新建mysql用户、组及目录

—新建一个msyql组

useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql —新建msyql用户禁止登录shell

在这里插入图片描述
表示已存在用户组
一般有了可以直接越过

6、改变目录属有者

#cd /usr/local/mysql
pwd
chown -R mysql .
chgrp -R mysql .

在这里插入图片描述

chown -R mysql /data/mysql

7、配置参数

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

在这里插入图片描述
此处需要注意记录生成的临时密码,如上文结尾处的:stx>jerpz8dO

bin/mysql_ssl_rsa_setup --datadir=/data/mysql

8 、修改系统配置文件

cd /usr/local/mysql/support-files
cp my-default.cnf /etc/my.cnf
cp mysql.server /etc/init.d/mysql
vim /etc/init.d/mysql

修改以下内容:
在这里插入图片描述

9、启动mysql

/etc/init.d/mysql start
在这里插入图片描述
运行mysql时多次出现了该错误后发现原因是之前装过mysql但未卸载干净
在这里插入图片描述
删除其中的mysql.sock.lock和mysql.sock文件
再次运行
在这里插入图片描述

–登陆

mysql -hlocalhost -uroot -p

–如果出现:-bash: mysql: command not found
–就执行: # ln -s /usr/local/mysql/bin/mysql /usr/bin --没有出现就不用执行

–输入第6步生成的临时密码

但在此时我输入生成的临时密码一直报错
在这里插入图片描述
所以通过跳过密码的方式进入数据库
在Linux,先进入/etc,修改my.cnf,任意一行加上"skip-grant-tables"。
重启mysql

再次执行mysql -hlocalhost -uroot -p 直接回车无需输入密码

在这里插入图片描述
mysql -hlocalhost -uroot -p

–修改密码

set password=password(‘root’);

在这里插入图片描述
–设置root账户的host地址(修改了才可以远程连接)

grant all privileges on . to ‘root’@’%’ identified by ‘root’;
flush privileges;

–查看表
mysql> use mysql;
mysql> select host,user from user;
–这里就可以使用远程连接测试了;
在这里插入图片描述
如提示不能成功连接,可能需要添加需要监听的端口
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

10 添加系统路径

vim /etc/profile
添加:
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile

11配置mysql自动启动

chmod 755 /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 345 mysql on

补充:
–退出mysql命令窗口
#exit
–查看mysql状态
#service mysql status
–停止mysql
#service mysql stop
–启动mysql
#service mysql start

附my.cnf(这是一个配置mysql配置文件,暂时可以不用管,如你想钻研 你可以百度或google “mysql my.cnf 配置详情”)

/etc/my.cnf

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
innodb_buffer_pool_size = 10G

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
log_bin
character-set-server=utf8
collation-server=utf8_bin
init-connect='SET NAMES utf8'
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /export/mysql/var
port = 3306
server_id = 22206
socket = /export/mysql/mysql.sock
binlog_format = statement
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
log_bin_trust_function_creators = on
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
lower_case_table_names=1

转载自:https://www.cnblogs.com/fanshudada/p/9781794.html 感谢博主提供学习资料

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值