Linux安装配置mysql

系统:CentOS 6.5 64位

安装包可以到mysql官网上去下载,不过需要翻墙,登陆,比较麻烦

推荐mysql下载地址

http://ftp.ntu.edu.tw/MySQL/Downloads


安装前检查系统是否已安装mysql

rpm -qa|grep -i mysql

如果已安装mysql的话使用以下语句进行卸载

yum -y remove mysql-libs-5.1*

或者

rpm -e mysql


1. 启动终端,进入/usr/local目录

cd /usr/local

2. 下载mysql安装包

wget http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.6/MySQL-5.6.31-1.linux_glibc2.5.x86_64.rpm-bundle.tar

3. 解压文件

tar –xvf MySQL-5.6.31-1.linux_glibc2.5.x86_64.rpm-bundle.tar

解压之后如下图:

4. 安装rpm文件

rpm-ivh xxx.rpm

5. 修改数据库密码

安装好mysql-server之后

会出现这样一段话

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER!

You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,

no other statement but 'SET PASSWORD' will be accepted.

See the manual for the semantics of the 'password expired' flag.

大概意思就是 一个随机的密码已经生成 可以在  '/root/.mysql_secret'. 中找到

cat /root/.mysql_secret

# The random password set for the root user at Mon Aug117:07:322016(local time): Vt5dWVuEDafMVmsW

这个Vt5dWVuEDafMVmsW就是随机的密码

启动服务

service mysql start

修改密码数据库密码

mysqladmin -u root -p password "test123"

Enter password: Vt5dWVuEDafMVmsW

6. 开启远程连接

默认mysql是没有开启远程连接的

登陆数据库。

mysql -u root -p

Enter password: test123

开启远程连接

grant all privileges on *.*  to 'root'@'%' identified by 'test123' with grant option;

第一个root表示用户名,%表示所有的电脑都可以连接,也可以设置某个ip地址运行连接,test123表示密码

执行下面命令立即生效

flush privileges;

7. 开启防火墙端口

#vim /etc/sysconfig/iptables

#在-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT之后添加

-A INPUT -mstate --state NEW -mtcp -p tcp --dport 3306-j ACCEPT

-A INPUT -mstate --state NEW -mtcp -p tcp --dport 7575-j ACCEPT

重启防火墙

service iptables restart

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容