MySQL 安装
Posted 那一剑的风情
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL 安装相关的知识,希望对你有一定的参考价值。
先下载mysql安装包
Linux:
环境:centos 7.0 x64
![](https://image.cha138.com/20210514/911d19a39c6246c880718f71a5576173.jpg)
![](https://image.cha138.com/20210514/7af3bbdf0cdc44e2b240aa01d5411b20.jpg)
4.安装数据库
./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data
这时候报错了,提示我们没有找到./scripts/mysql_install_db 这个里这个文件或者目录
因为 mysql_install_db 这个文件的目录已经改掉,在 bin/ 目录下面,那么我们再运行如下命令 ./bin/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/mysql/
这时候也报错了,让我们用 mysqld --initialize 来初始化
切到 mysql 用户,用 initialize 命令来初始化。
su root
su mysql
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data/
5.启动mysql:
报错:ERROR! The server quit without updating PID file
解决方法:
1.
先备份 MySQL 配置文件
sudo mv /etc/my.cnf /etc/my.cnf.backup
再启动
./mysql.server start
2. 查看/usr/local/mysql/data/ 目录下的错误日志 localhost.localdomain.err
解决具体错误。
效果:
6.添加自启动服务
切换到 root 用户执行
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
添加服务
chkconfig --add mysql
查看服务列表
chkconfig --list
如果看到mysql的服务,并且3,4,5都是on的话则成功,如果是off,则执行:
chkconfig --level 345 mysql on
7.连接数据库
报错:
解决方法:
1.停止运行的mysql
service mysql stop
2.带参数启动
/usr/bin/mysqld_safe --skip-grant-tables &
在启动 mysql 时不启动 grant-tables 授权表。请注意最后一个 & 号,必须要加。
3.启动后通过mysql命令直接进入,不需要密码.设置新密码即可
mysql
mysql> use mysql ;
mysql> update user set password=password(\'xxx\') where user=\'root\';(新版本mysql 用 update user set authentication_string=password(\'xxx\') where user=\'root\';)
mysql> exit
4.杀死当前的mysql进程,并重新启动mysql
ps -ef | grep mysql | grep -v grep | awk -F \' \' \'{print $2}\' | xargs kill -9
service mysql start
效果:
![](https://image.cha138.com/20210514/c6feefeaa471407e815bea6966d7b43c.jpg)
![](https://image.cha138.com/20210514/77a1c2a8cf3f4631a1bb94730da2c81e.jpg)
![](https://image.cha138.com/20210514/679a8d3859dd49a798589a2bb093e3d3.jpg)
![](https://image.cha138.com/20210514/26c0e6c891dd46abb8de8d4716f27b55.jpg)
![](https://image.cha138.com/20210514/4815555cd6cd4af8a4fbc5fa78bb89e5.jpg)
![](https://image.cha138.com/20210514/4511ce6d1eb84c9f8a2a7767fcb1c719.jpg)
![](https://image.cha138.com/20210514/e371a4faec2a4989b40bb0d77992e49e.jpg)
![](https://image.cha138.com/20210514/7925448e707f479e98d285899c9ab847.jpg)
![](https://image.cha138.com/20210514/5349002eb0394124a9e3ff9e2b8326a8.jpg)
![](https://image.cha138.com/20210514/aa6c92cdf29448acaab30637b8b9df82.jpg)
![](https://image.cha138.com/20210514/fb3a52c85cd041d6bdaafd85bc7aa3bd.jpg)
![](https://image.cha138.com/20210514/a0abf2c44c174bebb5cef9a0ad6f299d.jpg)
![](https://image.cha138.com/20210514/6230daf205aa4512bed8951ab9b688c8.jpg)
![](https://image.cha138.com/20210514/0a904e8574724cdfb1d1670e03879bac.jpg)
![](https://image.cha138.com/20210514/60bd96f79fab4410aa7fe2128dd539f1.jpg)
![](https://image.cha138.com/20210514/990ae7f2e4854564913a1feb2d86e7a1.jpg)
![](https://image.cha138.com/20210514/0ea0e4a251ad452ea67dcbc19344dc55.jpg)
校验:
以上是关于MySQL 安装的主要内容,如果未能解决你的问题,请参考以下文章