数据库之mysql

安装mysql-server时连同客户端与perl环境一起安装了

[root@localhost ~]# yum install mysql-server

Installing:

 mysql-server             x86_64    5.1.73-3.el6_5             base       8.6 M

Installing for dependencies:

 mysql                    x86_64    5.1.73-3.el6_5             base       894 k

 perl                     x86_64    4:5.10.1-136.el6_6.1       updates     10 M

 perl-DBD-MySQL           x86_64    4.013-3.el6                base       134 k

 perl-DBI                 x86_64    1.609-4.el6                base       705 k

 perl-Module-Pluggable    x86_64    1:3.90-136.el6_6.1         updates     40 k

 perl-Pod-Escapes         x86_64    1:1.04-136.el6_6.1         updates     32 k

 perl-Pod-Simple          x86_64    1:3.13-136.el6_6.1         updates    212 k

 perl-libs                x86_64    4:5.10.1-136.el6_6.1       updates    578 k

 perl-version             x86_64    3:0.77-136.el6_6.1         updates     51 k

Updating for dependencies:

 mysql-libs               x86_64    5.1.73-3.el6_5             base       1.2 M

 

gb2312_chinese_CI : 只支持简体中文

gb2312_BIN    :而gb2312_bin可以说是gb2312_chinese_ci的一个子集,

而且gb2312_BIN是二进制存储.区分大小写

数据库编码格式就意义不一样了

gbk_chinese_CI    支持简体中文和繁体

gbk_bin    解释同gb2312_BIN      对应gbk_chinese_CI

以root身份连接服务器,先查哪些账户没有口令
select host,user from mysql.user where Password = '';

然后为它们设置口令,有两种方法可以
1.set password for 'phpbb'@'%' = password('123qwe');    不需要刷新权限表
2.update mysql.user set password=password('123qwe') where user='root';
  flush privileges;                                     需要刷新权限表

查出账户有哪些权限
show grants for 'film'@'%';
revoke all on phpbb.* from 'phpbb'@'%';
revoke grant option on phpbb.* from 'phpbb'@'%';
drop user ‘phpbb’@‘%';


mysql> alter table 国产 rename to guochan;


习惯上函数用大写,但小写也可以
mysql> select now();
select ascii('f');
返回字符串str的第一个字符的ASCII值(str是空串时返回0),总是加单引号。
select CHAR(77,121,83,86,77);


查出账户有哪些权限

show grants            查看自己
show grants for 'film'@'%'; 查看别人


E:\TDDOWNLOAD\新建文件夹 (2)>dir >D:\program\PuTTY\a.txt
E:\TDDOWNLOAD\新建文件夹>dir >>D:\program\PuTTY\a.txt
D:\program\PuTTY>pscp.exe a.txt [email protected]:/root/
[root@localhost film]# tr -s ' ' ' ' <a.txt >b.txt
[root@localhost film]# cat name |grep "^\[" >name-1

 

mysql的四种启动方式:
1、mysqld
启动mysql服务器:./mysqld --defaults-file=/etc/my.cnf --user=root
客户端连接:
mysql --defaults-file=/etc/my.cnf
or
mysql -S /tmp/mysql.sock
 
2、mysqld_safe
启动mysql服务器:./mysqld_safe --defaults-file=/etc/my.cnf --user=root &
客户端连接:
mysql --defaults-file=/etc/my.cnf
or
mysql -S /tm/mysql.sock
 
3、mysql.server
cp -v /usr/local/mysql/support-files/mysql.server /etc/init.d/
chkconfig --add mysql.server
启动mysql服务器:service mysql.server {start|stop|restart|reload|force-reload|status}
客户端连接:同1、2
 
4、mysqld_multi
mkdir $MYSQL_BASE/data2
cat <<-EOF>> /etc/my.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /user/local/mysql/bin/mysqladmin
user = mysqladmin
password = mysqladmin
 
[mysqld3306]
port            = 3306
socket          = /tmp/mysql3306.sock
pid-file = /tmp/mysql3306.pid
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
 
[mysqld3307]
port            = 3307
socket          = /tmp/mysql3307.sock
pid-file = /tmp/mysql3307.pid
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data2
EOF
 
#mysql -S /tmp/mysql3306.sock
mysql>GRANT SHUTDOWN ON *.* TO 'mysqladmin'@'localhost' identified by 'mysqladmin' with grant option;
 
#mysql -S /tmp/mysql3307.sock
mysql>GRANT SHUTDOWN ON *.* TO 'mysqladmin'@'localhost' identified by 'mysqladmin' with grant option;
 
启动mysql服务器:./mysqld_multi --defaults-file=/etc/my.cnf start 3306-3307
关闭mysql服务器:mysqladmin shutdown
 
可参考<<MySql5.1参考手册>>
http://dev.mysql.com/doc/refman/5.1/zh/database-administration.html#server-side-scripts

你可能感兴趣的:(mysql)