linux下安装mysql
Posted 程序员果果
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux下安装mysql相关的知识,希望对你有一定的参考价值。
a、从mysql官网下载linux对应的三个文件
MySQL-server-5.6.30-1.el6.x86_64.rpm MySQL-devel-5.6.30-1.el6.x86_64.rpm MySQL-client-5.6.30-1.el6.x86_64.rpm
b、检查mysql是否已经安装,如果有安装则删除
[[email protected] ~]# rpm -qa | grep -i mysql [[email protected] ~]# yum -y remove mysql-libs*
c、安装mysql
[[email protected] rpm]# rpm -ivh MySQL-server-5.6.30-1.el6.x86_64.rpm [[email protected] rpm]# rpm -ivh MySQL-devel-5.6.30-1.el6.x86_64.rpm [[email protected] rpm]# rpm -ivh MySQL-client-5.6.30-1.el6.x86_64.rpm
d、修改mysql配置文件的位置
[[email protected] rpm]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf
e、初始化mysql和设置密码
[[email protected] rpm]# /usr/bin/mysql_install_db [[email protected] rpm]# service mysql start #查看root账号密码 [[email protected] rpm]# cat /root/.mysql_secret # The random password set for the root user at Wed Dec 11 23:32:50 2013 (local time): YsFtYd [[email protected] ~]# mysql -uroot –YsFtYd
#设置密码为root mysql> SET PASSWORD = PASSWORD(‘root); mysql> exit [[email protected] ~]# mysql -uroot -proot
f、远程登录用户设置
mysql> select host,user,password from user; +-----------------------+------+-------------------------------------------+ | host | user | password | +-----------------------+------+-------------------------------------------+ | localhost | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | | localhost.localdomain | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | | 127.0.0.1 | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | | ::1 | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | +-----------------------+------+-------------------------------------------+ 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
g、设置开机启动
[[email protected] ~]# chkconfig mysql on [[email protected] ~]# chkconfig --list | grep mysql mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
h、mysql的默认安装位置
#数据库目录 /var/lib/mysql/ #配置文件目录 /usr/share/mysql #相关命令目录 /usr/bin #启动脚本 /etc/init.d/mysql
i、修改字符集
[[email protected] /]# vi /etc/my.cnf [client] password=root 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=151 [mysql] default-character-set = utf8
j、远程连接mysql设置
①授权 [[email protected] /]# mysql -uroot -proot mysql> use mysql; mysql>GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘这里是你的密码‘ WITH GRANT OPTION; ②关闭防火墙 #关闭命令 [[email protected] /] service iptables stop #永久关闭防火墙 [[email protected] /] chkconfig iptables off
至此mysql就安装完成并配置完成
以上是关于linux下安装mysql的主要内容,如果未能解决你的问题,请参考以下文章