Linux下安装mysql数据库
l 检查是否已安装mysql的相关包
[root@localhost ~]# rpm -qa|grep -i mysql
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 (或者yum -y remove mysql-libs*这种删除指令
)
[root@localhost ~]# rpm -e MySQL-client-5.6.19-1.el6.x86_64 (或者yum -y remove mysql-libs*这种删除指令
)
[root@localhost ~]# rpm -e MySQL-devel-5.6.19-1.el6.x86_64 (或者yum -y remove mysql-libs*这种删除指令
)
l 删除/var/lib/mysql/
[root@localhost ~]#rm -fr /var/lib/mysql/
[root@localhost ~]#rm -fr /etc/my.cnf
[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 (这个用户是root,密码是:qKTaFZnl)
l 重置root密码为123456
mysql> SET PASSWORD = PASSWORD('1234abcd');
l 退出数据库
mysql> exit
l 验证密码
[root@localhost ~]# mysql -uroot -p1234abcd
设置mysql数据库允许远程登录:
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';
1.vim/etc/sysconfig/iptables
2、增加下面一行(在-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT后面)
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
3、重启防火墙
service iptables restart
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