码迷,mamicode.com
首页 > 数据库 > 详细

linux下的mysql安装

时间:2016-10-05 17:48:33      阅读:339      评论:0      收藏:0      [点我收藏+]

标签:

1、下载安装包
http://dev.mysql.com/downloads/mysql/#downloads
推荐下载通用安装方法的TAR包(http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar)。
2.看看自己安装过mysql;安装过则删除
[root@localhost Desktop]$ rpm -qa | grep mysql
mysql-libs-5.1.52-1.el6_0.1.x86_64
[root@localhost ~]# rpm -e mysql-libs-5.1.52.x86_64 --nodeps
[root@localhost ~]# 

3.创建mysql用户及组

[root@localhost ~]#groupadd mysql
[root@localhost ~]#useradd -r -g mysql mysql

之后可以查看一下成功创建没

[root@localhost ~]# cat /etc/group | grep mysql
[root@localhost ~]# cat /etc/passwd | grep mysql4.
4.将tar.gz解压到所要安装的目录
当然首先将mysql的。tar.gz包拖到对应的目录,使用winscp工具
技术分享
 
[root@promote local]# tar -zxvf mysql-5.7.15-linux-glibc2.5-i686.tar.gz

5. 解压成功后将文件改个名字

[root@promote local]# mv mysql-5.7.15-linux-glibc2.5-i686 mysql

6.安装和初始化数据库

[root@promote local]# mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
[root@promote local]# cd mysql
[root@promote local]#

 

----------------------
如果改变默认安装路径,则需要
1)/etc/my.cnf、/etc/init.d/mysqld中修改
basedir=‘/apps/mysql‘
datadir=‘/apps/mysql/data‘
2)创建ln
mkdir -p /usr/local/mysql/bin
ln -s /apps/mysql/bin/mysqld /usr/local/mysql/bin/mysqld
----------------------
[root@promote mysql]#cp -a ./support-files/my-default.cnf /etc/my.cnf

 问你是否覆盖时,yes

[root@promote local]#cp -a ./support-files/mysql.server  /etc/init.d/mysqld
[root@localhost mysql]# cd bin/
[root@localhost bin]# ./mysqld_safe --user=mysql &
[1] 1986
[root@promote bin]# 2016-10-05T16:34:17.548875Z mysqld_safe Logging to ‘/usr/local/mysql/data/promote.cache-dns.local.err‘.
2016-10-05T16:34:17.629041Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data


 

[root@promote bin]#  /etc/init.d/mysqld restart
Shutting down MySQL..2016-10-05T16:35:37.679390Z mysqld_safe mysqld from pid file /usr/local/mysql/data/promote.cache-dns.local.pid ended
                                                           [  OK  ]
Starting MySQL.                                            [  OK  ]
[1]+  Done                    ./mysqld_safe --user=mysql
[root@promote bin]# 

 设置开机启动mysql

[root@localhost bin]# chkconfig --level 35 mysqld on

 


7.初始化密码
mysql5.7会生成一个初始密码,用来登陆的
[root@localhost bin]# cat /root/.mysql_secret
# Password set for user ‘root@localhost‘ at 2016-10-06 00:29:51
Lfu+t9hi+ojn
[root@promote bin]# ./mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.15

Copyright (c) 2000, 2016, 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> SET PASSWORD = PASSWORD(‘123456‘);
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 8.添加远程访问权限

mysql> use mysql; 
mysql> update user set host = ‘%‘ where user = ‘root‘;
mysql>quit
[root@promote bin]# /etc/init.d/mysqld restart

 9.开放端口3306(也可以用其他端口)


[root@localhost bin]#/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT;
[root@localhost bin]#/etc/init.d/iptables status
[root@localhost bin]#/etc/rc.d/init.d/iptables save

 

 

 

linux下的mysql安装

标签:

原文地址:http://www.cnblogs.com/zhazhenyu1992/p/5932498.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!