MYSQL使用经验



一、安装


1.1Yum 安装


  groupadd mysql ##加mysql组##
  useradd  -g  mysql   mysql  ##加mysql用户,属组为mysql##
  yum install  mysql-server   ##通过yum方式安装,当然也可以编译安装##
  mkdir -p /opt/conf/mysql  ##创建配置文件目录##
  mkdir -p /opt/data/data_3306  ##创建数据库的数据目录,即库文件所在目录##
  cp /opt/apps/mysql/support-files/my-medium.cnf /opt/conf/mysql/mysql_3306.cnf ##拷贝模版配置文件##
  vi /opt/conf/mysql/mysql_3306.cnf  ##修改配置文件##
  chown -R mysql:mysql   /opt/conf/mysql   /opt/data/mysql  /opt/apps/mysql  ##修改目录权限##
  /opt/apps/mysql/scripts/mysql_install_db --datadir=/opt/data/mysql/data_3306/   --user=mysql  ##初始化数据库##
  /opt/apps/mysql/bin/mysqld_safe --defaults-file=/opt/conf/mysqld/my_3306.cnf   --user=mysql & ##启动数据库##


1.2源码安装
  tar xvfz  mysql-VERSION.tar.gz
  cd mysql-VERSION
  ./configure --prefix=/opt/apps_install/mysql-5.5.12  --with-charset=utf8 --with-extra-charsets=armscii8,ascii,big5,cp1250,.....,utf8 --with-plugins=innodb_plugin  
  make 
  make install
  ln  -s  /opt/apps/mysql  /opt/apps_install/mysql


二、语句


2.1 生成insert语句
   Mysqldump  参数  -d (表结构) --skip-extended-insert (一行一条Insert 语句)


2.2 服务界面
   打开运行窗口(win+R),输入services.msc回车


2.3 Insert into table_name select 语法
   insert into table_name(字段值1,字段列表2....) select 字段值1,字段值2... from another_table  
   //这里another表是必须存在的,而且不能写values关键字  
   select * into target_table from source_table;   
   //此句要求目标表不存在,在插入时候自动创建  


2.4分组 group by, 排序 取每条记录中,时间最大的一条记录
        t_stat_redis(id, authid,info, update_time)
        select a.authid, a.update_time from t_stat_redis a,
        ( select authid, max(update_time) update_time from t_stat_redis 
             where update_time >= '2014-05-09 16:18:14'  
            and  update_time <= '2014-05-09 16:23:44' 
        group by  authid, substring(update_time,1,16) ) b
        where a.authid = b.authid and a.update_time = b.update_time
        order by a.update_time desc;


2.5IP转十进制
   select inet_ntoa('ipv4') from 'table'


2.6表权限授权与解除
        grant all on *.* to dba@'%'
        revoke all on *.* from dba@'%'
        grant all privileges on amop.* to amop@localhost identified by 'xxxx'; 
        grant select,update,delete,insert on amop.* to amop@x.x.x.x  identified by  'xxxx';
        grant select on amoprd.* to amop@'10.90.3.%'  identified by  ''xxxx';
        grant select  on amop.* to amop@'%'  identified by 'xxxx';
        DELETE FROM user WHERE User="amop" and Host="%";
        flush privileges;


2.7AES与DES加解密算法
        select   hex(aes_encrypt(reverse('abc'), '123'));
        select   reverse(aes_decrypt(unhex(hex(aes_encrypt(reverse('abc'), '123'))), '123')); 

2.8查看系统字符集

        SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';

 


三、配置


3.1密码相关:
     ./mysqladmin -u root password ‘new_password’
          
3.2配置相关:  









 

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值