Linuix 下 MySQL 的安装

where is mysql
where is mysqld
yum list | grep mysql

输入mysql查找软件是否存在,及是否安装过mysql,且mysql的服务程序为mysqld

netstat -anp | grep 3306

查看端口3306是否被占用,以此端口作为mysql的端口

tar -zxvf mysql-523.tar.gz -C /opt

解压mysql.tar.gz 到opt

cd /opt/mysql
drwxr-xr-x.  2 root  root    6 4月  11 2018 bin 可执行文件(绿色带x)
                                            mysqld 服务程序
                                            mysqld__safe 安全启动文件
                                            mysqldump 备份数据
                                            mysql_install_db 初始化mysql数据库
drwxr-xr-x.  2 root  root    6 4月  11 2018 docs 文档
drwxr-xr-x.  2 root  root    6 4月  11 2018 include 程序定义的一些C语言头文件
                                            .h C语言头文件
drwxr-xr-x.  2 root  root    6 4月  11 2018 lib 库文件(不能单独运行)
                                            .so 为linux下的库文件
drwxr-xr-x.  2 root  root    6 4月  11 2018 LICNSE
drwxr-xr-x.  2 root  root    6 4月  11 2018 man 帮助文件
drwxr-xr-x. 10 123 123141 10月 11 09:13 README 数字代表没有任何权限的佚名用户
drwxr-xr-x.  2 root  root    6 4月  11 2018 sbin
drwxr-xr-x.  5 root  root   49 10月  9 17:59 share 共享文件夹
drwxr-xr-x.  2 root  root    6 4月  11 2018 support-files 支持文件
                                            mysql.server 专门启动mysql的shell文件
useradd mysql
cat /etc/gruop/ | grep mysql

新建mysql用户和组,并查看

chown -R mysql:mysql mysql-523

将mysql的权限归于mysql用户 mysql组

ls /etc/my.cnf
vi /etc/my.cnf
[mysqld] 配置文件中括号做节点,服务器节点
basedir=/opt/mysql57 数据库主程序包目录
datadir=/opt/mysql57/data 数据存储目录(数据),可自定义位置
socket=/tmp/mysql.sock 数据库提供给客户端连接服务器的连接点,放在/tmp/
port=3306 端口号默认3306
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# 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=/opt/mysq-523/errlog/mariadb.log 错误日志放在此文件夹下
pid-file=/opt/mysq-523/run/mariadb.pid 进程文件放在此文件夹下

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

查看my.cnf,若无则创建 

mkdir errlog run
cd errlog 
touch mariadb.log # errlog下mariadb.log需要自行创建,pid自动创建
mkdir data #创建数据库
chown -R mysql:mysql mysql-523 # 再次将新文件架和文件归属于mysql用户和组

 创建错误日志和进程 的文件夹 

cd /opt/mysql-523
mkdir data 创建数据库
cat bin
cat mysql_install_db 初始化mysql数据库
./mysqld --initialize --user=mysql 
--basedir数据库主程序包目录=/opt/mysq-523 
--datadir数据存储目录=/opt/mysql-523/data

初始化mysql数据库 

 

 如出现data中已有字段,则会报错,解决方法

cd ../data | rm -f *
再执行初始化

 初始化后的最后一行为mysql初始密码

cd /opt/mysql-523/bin/mysql --defaults-files=/etc/my.cnf --user=mysql & 告诉程序使用配置文件启动 &表示切到后台
./mysql -u root -p 然后输入密码
password:初始密码进入失效
mysql> set password=password("123456");
mysql> show databases;  打开数据库
mysql> use mysql 使用数据库
mysql> select host,user from user; 查看用户
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option; # ALL PRIVILEGES:当前用户的所有权限
ON:介词
*.*:当前用户对所有数据库和表的相应操作权限
TO:介词
‘root’@’%’:权限赋给root用户,所有ip都能连接
IDENTIFIED BY ‘123456’:连接时输入密码,密码为123456
WITH GRANT OPTION:允许级联赋权

mysql> flush privileges; 刷新权限

后两个命令就是给root用户开远程权限使用的

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值