Linux安装MySQL

安装MySQL

学习笔记上传,Linux 系统CentOS7安装Mysql

卸载自带数据库

查看本机安装的mariadb数据库

[root@localhost]# rpm -qa|grep mariadb

卸载mariadb

# sudo rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps

下载MySQL5.5
官方网站:https://dev.mysql.com/downloads ,找到合适版本下载通过Xftp传送
解压通过指令:

# tar -zxvf mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz

安装
目录:/usr/local/mysql
1、创建免登陆用户并授权
#创建用户

useradd -s /sbin/nologin -M mysql

#授权

chown -R mysql:mysql /usr/local/mysql
chmod -R 775 /usr/local/mysql

2、安装
指令,在mysql目录下:

# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

在这里插入图片描述

3、修改配置脚本

#修改脚本
vi ./support-files/mysql.server
#修改下面内容
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
#拷贝脚本
cp ./support-files/mysql.server /etc/init.d/mysqld
#授权
chmod 775 /etc/init.d/mysqld
4、修改配置文件
# vi /etc/my.cnf

内容如下:

[client] port=3306 default-character-set=utf8   [mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data socket=/usr/local/mysql/mysql.sock



# 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=/usr/local/mysql/log/error.log
pid-file=/usr/local/mysql/data/mysql.pid


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

5、设置开机启动和环境变量

#将数据库服务添加到开机启动
chkconfig --add mysqld
chkconfig mysqld on
 #编辑环境变量
vim /etc/profile
#最后加入下面一句
export PATH=$PATH:/usr/local/mysql/bin
#环境变量生效
source /etc/profile

6、启动

# service mysqld start

报错及解决
报错1
在启动过程中出现图片: https://uploader.shimo.im/f/K7782uKtQ10gj7ha.PNG
解决方案:在提示目录下创建该文件即可解决。
报错2
使用以下指令登陆

# mysql -uroot 

登录后出现报错
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
解决方案:
先查找mysql.sock位置:
图片: https://uploader.shimo.im/f/IkAYb2Kpc8s9WDRZ.PNG 在/tmp/mysql.sock创建该文件的软连接:

# ln -s /usr/local/mysql/mysql.sock /tmp/mysql.sock

再登陆,出现以下则成功
图片: https://uploader.shimo.im/f/whJCeIarTwIZpZ9n.PNG

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值