安装时用的Linux为rhel6.3 x86_64,用的MySQL为mysql5.6.26 x86_64,下载地址:www.oracle.com
安装方式为rpm二进制安装,所需要的两个mysql rpm安装包为:
MySQL-server-5.6.26-1.el6.x86_64.rpm
MySQL-client-5.6.26-1.el6.x86_64.rpm
上面的两个安装包也可以从以下的地址下载:
http://download.csdn.net/detail/jiaping0424/9503594
http://download.csdn.net/detail/jiaping0424/9503595
关于这两个包的作用和关系自己百度吧,这里不再赘述。
利用rpm二进制安装方式来安装mysql过程非常简单,rpm命令在安装时常用的参数是-hiv,其中i表示将安装指定的rmp软件包,v表示输出安装时的详细信息,h表示在安装期间出现“#”号来显示目前的安装进度。
如果安装前系统已经存在相关组件,则在安装时会报冲突相关错误,这里避免报错先卸载与mysql相关的组件。
[root@web1 ~]# rpm -qa|grep mysql
mysql-libs-5.1.61-4.el6.x86_64
[root@web1 ~]#
[root@web1 ~]# rpm -e --nodeps mysql-libs-5.1.61-4.el6.x86_64
[root@web1 ~]# rpm -qa|grep mysql
[root@web1 ~]#
[root@web1 ~]# rpm -hiv MySQL-server-5.6.26-1.el6.x86_64.rpm
warning: MySQL-server-5.6.26-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:MySQL-server ########################################### [100%]
[root@web1 ~]# rpm -hiv MySQL-client-5.6.26-1.el6.x86_64.rpm
warning: MySQL-client-5.6.26-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:MySQL-client ########################################### [100%]
[root@web1 ~]#
[root@web1 ~]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf
[root@web1 ~]# /usr/bin/mysql_install_db
[root@web1 ~]# service mysql start
Starting MySQL.[确定]
[root@web1 ~]#
查看root账号密码
[root@web1 ~]# cat /root/.mysql_secret
# The random password set for the root user at Fri Apr 22 00:52:07 2016 (local time): 3IYLCgGex2Y7KWvR [root@web1 ~]#
利用上面的密码登录:
[root@web1 ~]# mysql -uroot -p3IYLCgGex2Y7KWvR
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.26
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
修改密码为123456:
mysql> SET PASSWORD = PASSWORD('123456');
Query OK, 0 rows affected (0.02 sec)
mysql> exit
Bye
再用新密码登录:
[root@web1 ~]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
[root@web1 ~]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select host,user,password from user;
+-----------+------+-------------------------------------------+
| host | user | password |
+-----------+------+-------------------------------------------+
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| web1 | root | *5B4AC10888F4F9D9A8CD55A78EF1EA2D0322B013 |
| 127.0.0.1 | root | *5B4AC10888F4F9D9A8CD55A78EF1EA2D0322B013 |
| ::1 | root | *5B4AC10888F4F9D9A8CD55A78EF1EA2D0322B013 |
+-----------+------+-------------------------------------------+
4 rows in set (0.00 sec)
mysql> update user set password=password('123456') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 4 Changed: 3 Warnings: 0
mysql> update user set host='%' where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
[root@web1 ~]#
[root@web1 ~]# chkconfig mysql on
[root@web1 ~]# chkconfig --list | grep mysql
mysql 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[root@web1 ~]#
/var/lib/mysql/ #数据库目录
/usr/share/mysql #配置文件目录
/usr/bin #相关命令目录
/etc/init.d/mysql #启动脚本
配置/etc/my.cnf文件、修改数据存放路径、mysql.sock路径以及默认编码utf-8
[root@web1 ~]# vi /etc/my.cnf
[client]
password = 123456
port = 3306
default-character-set=utf8
[mysqld]
port = 3306
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
#(注意linux下mysql安装完后是默认:表名区分大小写,列名不区分大小写; 0:区分大小写,1:不区分大小写)
lower_case_table_names=1
#(设置最大连接数,默认为 151,MySQL服务器允许的最大连接数16384; )
max_connections=1000
[mysql]
default-character-set = utf8
show variables like '%collation%';
show variables like '%char%';
注:为了使博客更加完善,便于更好的分享,请读者为文章中的错误进行指正,博主会定期更正,谢谢!
Keep fighting.
Warrior
2016.4.27
– The End –