[centos] 安装mysql
安装MySQL。
[root@sample ~]# sudo yum -y install mysql-server
配置MySQL
[root@sample ~]#vim /etc/my.cnf
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 如果2--5为on的状态就OK
启动MySQL服务
[root@sample ~]#/etc/rc.d/init.d/mysqld start
用root用户登录MySQL服务器
[root@sample ~]# mysql -u root
查看用户信息
mysql> select user,host,password from mysql.user;
+------+------------------------------+---------------+| user | host | password |+------+------------------------------+---------------+| root | localhost | | ← root密码为空 | root | sample.centospub.com | | ← root密码为空| | sample.centospub.com | || | localhost | ||root | % |XXX || | | |+------+------------------------------+---------------+
设置root密码
mysql> set password for root@localhost=password('在这里填入root密码');
设置root密码
set password for root@'sample.centospub.com'=password('在这里填入root密码');
设置root密码
mysql> set password for root@'xxx'=password('xxx');
退出MySQL服务器
mysql> exit
通过密码用root登录
[root@sample ~]#mysql -u root -p
Enter password: ← 在这里输入密码
通过密码用root登录
[root@sample ~]# mysql -u root -h sample.centospub.com -p
Enter password: ← 在这里输入密码
删除匿名用户
mysql> delete from mysql.user where user='';
建立对test数据库有完全操
mysql> grant all privileges on test.* to centospub@localhost identified by '在这里定义密码';
连接到数据库
mysql> use test
在数据库中建立表
mysql> create table test(num int, name varchar(50));
查看表信息
mysql> show tables;
查看已存在的数据库
mysql> show databases;
删除名为test的数据库
mysql> drop database test;
刷新,使以上操作生效
mysql> flush privileges;