MySQL5.6安装(RPM)笔记

1. 检查MySQL是否安装,如果有安装,则移除(rpm –e 名称)
[root@localhost ~]# rpm -qa | grep -i mysql
mysql-libs-xxxxxxxxxx.x86_64
[root@localhost ~]# yum -y remove mysql-libs* --nodeps
[root@localhost ~]# rpm –e --nodeps mysql-libs*

2. 安装MySQL,并修改配置文件位置
[root@localhost rpm]# rpm -ivh MySQL-server-5.6.15-1.el6.x86_64.rpm
#MySQL-client - MySQL 客户端程序,用于连接并操作Mysql服务器。
[root@localhost rpm]# rpm -ivh MySQL-devel-5.6.15-1.el6.x86_64.rpm
#MySQL-devel - 库和包含文件,如果你想要编译其它MySQL客户端,例如Perl模块,则需要安装该RPM包。
[root@localhost rpm]# rpm -ivh MySQL-client-5.6.15-1.el6.x86_64.rpm

#修改配置文件位置
[root@localhost rpm]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf

3.配置/etc/my.cnf文件,修改数据存放路径、mysql.sock路径以及默认编码utf-8.
[mysqld]

# ###################公共参数#########################################
# basedir = .....
# datadir = .....
port = 3306
# server_id = .....
# socket = .....

# ###################主要参数#########################################
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

# ###################其它参数#########################################
# 缓存innodb打开的数据. 建议,专用服务器设置:70%, 其它设置: 10%.
innodb_buffer_pool_size = 1024M

# 操作DDL/DML/DCL产生的2进制格式log日志,用于主从服务器之间的同步数据
# log_bin = master-bin
# log_bin_index=master-bin.index
# relay_log=slave-bin
# relay_log_index=slave-bin.index

# 慢查询日志
# long_query_time=10
# slow_query_log={0|1}
# slow_query_log_file=/var/lib/mysql/log-slow-queries.log

# 字符集
character_set_server = utf8
character_set_client = utf8
collation_server = utf8_general_ci

# mysql安装完后, 表名默认区大小写. 0: 区分大小写; 1: 不区分大小写.
lower_case_table_names = 1

# 最大连接数,默认:151(允许的最大连接数16384).
max_connections = 500

# 免密码登入
# skip-grant-tables

4. 初始化MySQL及设置密码
[root@localhost rpm]# /usr/bin/mysql_install_db
[root@localhost rpm]# service mysql start
[root@localhost rpm]# cat /root/.mysql_secret #查看root账号密码
# The random password set for the root user at Wed Dec 11 23:32:50 2013 (local time): admin
[root@localhost ~]# mysql -uroot –padmin
mysql> SET PASSWORD = PASSWORD('123456'); #设置密码为123456
mysql> exit
[root@localhost ~]# mysql -uroot -p123456

注意: 初始密码有大写写问题;

5. 允许远程登陆
mysql> use mysql;
mysql> select host, user, password , password_expired from user;

host user password password_expired
--------- ------ ----------------------------------------- ------------------
% root *F33961124480E2059C6CAA1FD02EEA6B73D8D6F5 N
localhost hive1 *F33961124480E2059C6CAA1FD02EEA6B73D8D6F5 N

mysql> update user set password=password('123456') where user='root';
mysql> update user set host='%' where user='root' and host='localhost';
mysql> flush privileges;
mysql> exit

注意:password_expired 为Y表示过期, N表示未过期

6. 设置开机自启动
[root@localhost ~]# chkconfig mysql on
[root@localhost ~]# chkconfig --list | grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off

7. MySQL的默认安装位置
/var/lib/mysql/ #数据库目录
/usr/share/mysql #配置文件目录
/usr/bin #相关命令目录
/etc/init.d/mysql #启动脚本

8. 常用命令
启动: service mysql start
停止: service mysql stop
查看状态: service mysql status
数据导入:LOAD DATA LOCAL INFILE '/home/package/script/table_data.csv' INTO TABLE table_name COLUMNS TERMINATED BY ',' LINES TERMINATED BY '\r\n';
数据导出:mysqldump -uroot -padmin schema > file.sql;
链接数据库:mysql -uroot -p密码

上一篇:Windows加载器与模块初始化


下一篇:CDH:cdh5环境mkdir: Permission denied: user=root, access=WRITE, inode="/user":hdfs:hadoop:drwxr-xr-x