1. root 用户登陆服务器;
2. apt-get update
3. apt-get install mysql-server mysql-client 注意设置root密码;
4. mysql -uroot -p 进行配置
5. 更换 root 密码:
use mysql;
set password for 'root'@'localhost' = PASSWORD('new password');
flush privileges;
6. 创建用户:
insert into user(Host, User, Password) values ('localhost', 'test', '123456');
flush privileges;
7. 创建数据库:
create database test;
创建表
create table 'test' (id int unsigned primary key auto_increment);
8. 赋予用户 test 访问表的权限
grant all privileges on ty.* to ty@localhost identified by '123456';
grant all privileges on ty.* to ty@'202.192.138.22' identified by '123456';
flush privileges;
9. 让 msyql 绑到本地IP 上,这样可以远程连接数据库;
service mysql stop
vim /etc/mysql/my.cnf
找到下面这行然后注释掉,在起动 mysql;
bind-address = 127.0.0.110. 修改默认存储路径
mkdir -p /data/mysql
cd /data/msyql
cp -rf /var/lib/mysql/* .
vim /etc/mysql/my.cnf
找到下面这行,把内容换为 datadir = /data/msyql
bind-address = 127.0.0.1chown -R mysql:mysql /data/mysql
vim /etc/apparmor.d/usr.sbin.mysqld