MySql基础知识(经典版)
一、mysql 的管理
1
、连接
Mysql
格式: mysql -h主机地址 -u用户名 -p用户密码
例1:连接到本机上的MYSQL。
首先在打开DOS窗口,然后进入目录 mysqlbin,再键入命令mysql -uroot -p,回车后提示你输密码,如果刚安装好MYSQL,超级用户root是没有密码的,故直接回车即可进入到MYSQL中了,MYSQL的提示符是:mysql>
例2:连接到远程主机上的MYSQL。假设远程主机的IP为:110.110.110.110,用户名为root,密码为abcd123。则键入以下命令:
mysql -h110.110.110.110 -uroot -pabcd123
(注:u与root可以不用加空格,其它也一样)
2
、退出MYSQL命令: exit (回车)
3
、
修改密码
格式:mysqladmin -u用户名 -p旧密码 password 新密码
1) mysqladmin -u用户名 -p旧密码 password 新密码
例:mysqladmin -u root password 21century
注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。
2)直接修改user表的root用户口令:
mysql> user mysql;
mysql> update user set pasword=password('21century') where user='root';
mysql> flush privileges;
注:flush privileges的意思是强制刷新内存授权表,否则用的还是缓冲中的口令。
4
、测试密码是否修改成功
1)不用密码登录
[root@test1 local]# mysql
ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)
显示错误,说明密码已经修改。
2)用修改后的密码登录
[root@test1 local]# mysql -u root -p
Enter password: (输入修改后的密码21century)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 177 to server version: 3.23.48
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
成功!
这是通过mysqladmin命令修改口令,也可通过修改库来更改口令
5、增加新用户
(注意:和上面不同,下面的因为是MYSQL环境中的命令,所以后面都带一个分号作为命令结束符)
格式:grant select on 数据库.* to 用户名@登录主机 identified by "密码"
例1、增加一个用户test1密码为abc,让他可以在任何主机上登录,并对所有数据
相关文档:
手动建表:
CREATE TABLE `excel` (
`id` int(11) DEFAULT NULL,
`name` varchar(50) DEFAULT NULL,
`passwd` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=gb2312; 注意是gb2312
然后在连接数据库时加上:
useUnicode=true&characterEncoding=gb2312.
就ok啦! ......
I found a solution to anyone else who may be having this problem.
First start mysql using skip grant tables
root@ns1 [/var/lib/mysql/mysql]# service mysql start --skip-grant-tables
Starting MySQL [ OK ]
now with mysql started, you can repair the mysql/user table
root@ns1 [/var/lib/mysql ......
所以除了给账户权限以外 还有修改 /etc/mysql/my.cnf
找到 bind-address = 127.0.0.1 修改为 bind-address = 0.0.0.0
重启mysql : sudo /etc/init.d/mysql restart
否则会报 ERROR 2003 (HY000): Can't connect to MySQL server on 'x.x.x.x' (111)
好吧 我是mysql菜鸟 以前都是走localhost的
......
<?php
/**
* 操作mysql
的基础类,其它与mysql有关的类都继承于此基类
*
* 此class中的$table都是已经包含表前缀的完整表名
*
* ver 20090717
* 使用范例
* $db = new DB('localhost','root','password','database','utf8');
* $db->debug = true;
* $db->primaryKeys = array (
* 'table_1 ......