Ubuntu安装MySQL

安装MySQL

安装MySQL:

sudo apt-get update
sudo apt-get install mysql-server

配置MySQL:

sudo mysql_secure_installation

检查是否安装成功:

systemctl status mysql.service

如果出现以下内容则安装成功:

  *
其他内容
  *
Active: active (running)
  *
其他内容
  *
Started MySQL Community Server.

其他命令

sudo systemctl mysql start          # 启动MySQL
sudo systemctl mysql stop           # 停止MySQL
sudo systemctl mysql restart        # 重启MySQL
sudo systemctl start mysql          # 启动MySQL
mysqladmin -p -u root version       # 检查MySQL版本信息

测试MySQL

mysql -uroot -p                     # 输入密码登录MySQL数据库
show variables like 'character%';   # 查看MySQL的默认字符集

创建用户与授权

CREATE USER 'admin'@'%' IDENTIFIED BY 'admin';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;

字符集配置

[client]
  default_character_set=utf8

[mysqld]
  character_set_server=utf8

[mysql]
  default_character_set=utf8
posted @ 2021-05-12 21:10  心如光  阅读(65)  评论(0编辑  收藏  举报