MySQL-Linux
安装
sudo apt install -y mysql-server
开启MySQL服务
sudo systemctl start mysql
MySQL设置为开机自启动:
sudo systemctl enable mysql
检查MySQL状态
sudo systemctl status mysql
登录
mysql -uroot -p;
进入系统库
use mysql;
设置密码,localhost 本地访问,% 可远程访问
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
修改host
update user set host = '%' where user = 'root';
创建新用户
CREATE USER 'username'@'host' IDENTIFIED BY 'password';
查看用户访问端口
select user,host from user;
刷新缓存
flush privileges;
修改 /etc/mysql/mysqld.conf.d/mysqld.cnf,实现远程访问
bind-address = 0.0.0.0
重启服务
sudo systemctl restart mysql
创建数据库
CREATE DATABASE 库名;
显示数据库
show databases;
为root授予所有权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost';
关闭服务
sudo systemctl stop mysql
彻底卸载
sudo apt purge mysql-*
sudo rm -rf /etc/mysql/ /var/lib/mysql
sudo apt autoremove
sudo apt autoclean
C语言安装MySQL库
1 | sudo apt-get install libmysqlclient-dev |