跳到主要内容

安装

mac 下点击安装后配置环境。

可使用 rpm -qa | grep mysql 查看系统是否自带 mysql 。

卸载:

rpm -e mysql -- 普通卸载
rpm -e nodeps mysql -- 强力卸载

环境配置 (mac)

在 ~/.bash_profile 文件中添加:

export PATH=$PATH:/usr/local/mysql/bin
export PATH=$PATH:/usr/local/mysql/support-files
source ~/.bash_profile # 保存上述编辑后执行
echo $PATH # 查看编辑后的结果

在 /etc/profile 文件添加:

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

状态查看

sudo mysql.server status # 状态查看
sudo mysql.server start # 开启 sql
sudo mysql.server stop # 关闭 sql
sudo mysql.server restart # ~~重启 sql~~
systemctl restart mysqld.service # 重启 sql
systemctl stop mysqld.service # 停止 sql

上述命令(可能)会在 mac 报错,因为在 mac 上 mysql 的位置为 设置-〉最底端 ( mysql )

服务器

安装(安装前需要卸载干净):

wget http://repo.mysql.com/ [mysql......noarch.rpm](https://dev.mysql.com/downloads/repo/yum/)
yum update
yum install mysql-server # 安装服务
sudo chown -R mysql:mysql /var/lib/mysql # 更改文件所属人
sudo chmod -R 705 /var/lib/mysql # 更改文件权限

初始化:

mysqld --initialize

启动:

systemctl start mysqld

查看状态:

systemctl status mysqld

版本查看:

mysqladmin --version

登录

mysql -u root -p

端口号查看

show global variables like "port";

设置密码

set password for 'root'@'localhost' = {新密码 }

更改密码

alter user span class="dust">root'@'localhost'
> identified with mysql_native_password by '新密码';

刷新密码权限

flush privileges

强密码模式改为弱密码模式

alter user span class="dust">root'@'localhost'
> identified by '密码' password expire never;

卸载

停止服务

service mysql stop

删除 mysql 软件包

yum remove mysql

删除 mysql 服务

rm -rf /etc/init.d/mysql

删除 mysql 配置文件

find / -name my.cnf
rm -f my.cnf

删除 mysql 用户和用户组

userdel mysql
groupdel mysql