1.1 安装Mysql
1.1.1 检查
l 检查是否已安装mysql的相关包
[root@localhost ~]# rpm -qa|grep -i mysql
一般情况下,centeros系统中会存在mysql-lib的文件,需要卸载
卸载mysql-lib命令如下:
#rpm -e --nodeps mysql-libs-5.1.61-4.el6.x86_64
MySQL-server-5.6.19-1.el6.x86_64
MySQL-client-5.6.19-1.el6.x86_64
MySQL-devel-5.6.19-1.el6.x86_64
l 若已安装移除rpm包
[root@localhost ~]# rpm -e MySQL-server-5.6.19-1.el6.x86_64
[root@localhost ~]# rpm -e MySQL-client-5.6.19-1.el6.x86_64
[root@localhost ~]# rpm -e MySQL-devel-5.6.19-1.el6.x86_64
l 删除/var/lib/mysql/
[root@localhost ~]#rm -fr /var/lib/mysql/
[root@localhost ~]#rm -fr /etc/my.cnf
1.1.2 安装
l 上传安装包
[root@localhost ~]# cd soft/
上传完成之后检查上传的mysql rpm包的权限:ls -al
如果没有写的权限,则需要修改rpm包的权限:chmod -R 777 MySQL-client-5.6.19-1.el6.x86_64.rpm MySQL-devel-5.6.19-1.el6.x86_64.rpm MySQL-server-5.6.19-1.el6.x86_64.rpm
[root@localhost soft]# ll
drwxr-xr-x 2 root root 4096 Sep 9 20:44 jdk
-rwxr-xr-x. 1 root root 18360416 Jul 9 16:15 MySQL-client-5.6.19-1.el6.x86_64.rpm
-rwxr-xr-x. 1 root root 3368712 Jul 9 16:14 MySQL-devel-5.6.19-1.el6.x86_64.rpm
-rwxr-xr-x. 1 root root 54592892 Jul 9 16:13 MySQL-server-5.6.19-1.el6.x86_64.rpm
l 安装
[root@localhost soft]# rpm -ivh MySQL-server-5.6.19-1.el6.x86_64.rpm
[root@localhost soft]# rpm -ivh MySQL-devel-5.6.19-1.el6.x86_64.rpm
[root@localhost soft]# rpm -ivh MySQL-client-5.6.19-1.el6.x86_64.rpm
l 修改配置文件位置
[root@localhost soft]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf
l 初始化MySQL
[root@localhost soft]# /usr/bin/mysql_install_db
l 启动服务
[root@localhost soft]# service mysql start
l 查看root账号密码
[root@localhost soft]# cat /root/.mysql_secret
# The random password set for the root user at Wed Dec 11 23:32:50 2013 (local time): qKTaFZnl
注:命令的输出'qKTaFZnl'即为密码
l 登陆数据库
[root@localhost ~]# mysql -uroot –pqKTaFZnl
l 重置root密码为123456
mysql> SET PASSWORD = PASSWORD('1234abcd');
l 退出数据库
mysql> exit
l 验证密码
[root@localhost ~]# mysql -uroot -p1234abcd
l 允许远程登陆
安装后的配置
1)登陆mysql数据库
mysql> use mysql;
2)查询主机,用户名,密码
mysql> select host,user,password from user;
+-----------------------+------+-------------------------------------------+
| host | user | password |
+-----------------------+------+-------------------------------------------+
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost.localdomain | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 |
| 127.0.0.1 | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 |
| ::1 | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 |
+-----------------------+------+-------------------------------------------+
3)更新用户表,重置root密码
mysql> update user set password=password('1234abcd') where user='root';
4)允许远程登陆
mysql> update user set host='%' where user='root' and host='localhost';
5)刷新权限
mysql> flush privileges;
6)退出server
mysql> exit
l 设置开机自启动
[root@localhost ~]# chkconfig mysql on
1)查看启动级别--以下为正常
[root@localhost ~]# chkconfig --list | grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
l MySQL的默认安装位置--查看目录或文件是否存在
----------------------------------------------------------------------
1) /var/lib/mysql/ #数据库目录
2) /usr/share/mysql #配置文件目录
l 修改字符集和数据存储路径
配置/etc/my.cnf和/usr/my.cnf文件,修改数据存放路径、mysql.sock路径以及默认编码utf-8.
vim /etc/my.cnf
配置/etc/my.cnf,vi /etc/my.cnf
[mysqld]
#log-slow-queries=/var/log/mysqllog/myslow.log
#long_query_time=1
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
lower_case_table_name=1
character-set-server=utf8
collation-server=utf8_general_ci
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-slow-queries=/var/log/mysqllog/myslow.log
long_query_time=1
配置/usr/my.cnf,vi /usr/my.cnf
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
##max connections
max_connection=1000
重启mysql服务
service mysql restart
1.2 在CentOS系统中防火墙默认是阻止3306端口的,我们要是想访问mysql数据库,我们需要这个端口,命令如下:
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
我们需要保存我们的操作,命令如下:
/etc/rc.d/init.d/iptables save
此时我们可以查看端口的状态,命令如下:
/etc/init.d/iptables status
当然如果你打开其他端口也一样,只需要把这个端口号换乘你需要的端口号即可。
到此mysql安装成功!!