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是否已经安装,如果有安装则删除
[root@localhost ~]# rpm -qa | grep -i mysql [root@localhost ~]# yum -y remove mysql-libs*
c、安装mysql
[root@localhost rpm]# rpm -ivh MySQL-server-5.6.30-1.el6.x86_64.rpm [root@localhost rpm]# rpm -ivh MySQL-devel-5.6.30-1.el6.x86_64.rpm [root@localhost rpm]# rpm -ivh MySQL-client-5.6.30-1.el6.x86_64.rpm
d、修改mysql配置文件的位置
[root@localhost rpm]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf
e、初始化mysql和设置密码
[root@localhost rpm]# /usr/bin/mysql_install_db [root@localhost rpm]# service mysql start #查看root账号密码 [root@localhost rpm]# cat /root/.mysql_secret # The random password set for the root user at Wed Dec 11 23:32:50 2013 (local time): YsFtYd [root@localhost ~]# mysql -uroot –YsFtYd
#设置密码为root mysql> SET PASSWORD = PASSWORD('root); mysql> exit [root@localhost ~]# 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、设置开机启动
[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
h、mysql的默认安装位置
#数据库目录 /var/lib/mysql/ #配置文件目录 /usr/share/mysql #相关命令目录 /usr/bin #启动脚本 /etc/init.d/mysql
i、修改字符集
[root@localhost /]# 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设置
①授权 [root@localhost /]# mysql -uroot -proot mysql> use mysql; mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '这里是你的密码' WITH GRANT OPTION; ②关闭防火墙 #关闭命令 [root@localhost /] service iptables stop #永久关闭防火墙 [root@localhost /] chkconfig iptables off
至此mysql就安装完成并配置完成
关注我的公众号,精彩内容不能错过
作者:程序员果果
出处:blog.itwolfed.com
欢迎关注公众号——《程序员果果》 ,分享SpringBoot、SpringCloud、Dubbo、Golang、Docker相关知识与技巧。
原创 Java 博客,点我看看?