Ubuntu虚拟机安装mysql

版本:Ubuntu_1804mysql_5.7

  1. sudo apt-get update
  2. sudo apt-get install mysql-server-5.7
  3. vim /etc/mysql/mysql.conf.d/mysqld.cnf
    注释掉bind-addressskip-external-locking并保存
  4. mysql默认username为root,密码为空,
    可以执行sudo mysql_secure_installation按照提示初始化密码。
  5. sudo mysql -u root进入mysql命令行后,新建一个mysql管理员账户。
    参照:host-xxx-xx-xxx-xxx-is-not-allowed-to-connect-to-this-mysql-server
    具体配置命令:
mysql> CREATE USER '${user_name}'@'localhost' IDENTIFIED BY '${some_pass}';
mysql> GRANT ALL PRIVILEGES ON *.* TO '${user_name}'@'localhost'
    ->     WITH GRANT OPTION;
mysql> CREATE USER '${monty}'@'%' IDENTIFIED BY '${some_pass}';
mysql> GRANT ALL PRIVILEGES ON *.* TO '${user_name}'@'%'
    ->     WITH GRANT OPTION;
  1. 使用mysql客户端,输入ip、端口、新建的mysql管理员账户、密码即可登录,大功告成。

你可能感兴趣的:(Ubuntu虚拟机安装mysql)