下载
sudo apt-get install mysql-server
初始化
sudo mysql_secure_installation
配置设置
#1
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N (我的选项)
#2
Please set the password for root here...
New password: (输入密码)
Re-enter new password: (重复输入)
#3
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (我的选项)
#4
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network...
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y (我的选项)
#5
By default, MySQL comes with a database named 'test' that
anyone can access...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的选项)
#6
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的选项)
mysql服务操作(状态,停止,启动,重启)
service mysql status|stop|start|restart
登陆mysql (-u用户名 -p密码)
sudo mysql -uroot -p
Workbench连接数据库
进入mysql之后操作如下指令
- grant 权限1,权限2,...权限n on 数据库名称.表名称 to 用户名@用户地址 identified by '连接密码'; 进行权限设置
1.权限 可以多个,共14种,分别为:select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等,其中赋予全部权限时使用all privileges
2.数据名称.表名称 如果用.表示,说明赋予用户服务器上所有数据库所有表的权限。
3.用户名 即用于登录数据库的名称,如root
4.用户地址 可以是localhost,可以是ip地址、机器名字、域名等等,也可以用%表示任何连接地址。
连接密码 不能为空,否则会赋予权限失败。
GRANT ALL PRIVILEGES ON *.* TO 用户名@localhost IDENTIFIED BY "密码";
创建完就可以用MySQL Workbench连接了。
如果还无法连接。
可以进入mysql目录 /etc/mysql/ 进行查看debian.cnf文件。有用户密码可以直接连接。