阿里云服务器安装MySql
阿里云安装MySql
阿里云ECS服务器CentOS7上
1.服务器更新并重启命令
yum -y update
reboot
2.检查是否已经安装,如果已经安装先删除以前版本(tab 补全命令)
检查命令:rpm -qa | grep mysql
卸载命令:yum remove MySQL-server MySQL-devel
3.安装MySql
1. 创建下载安装包的目录(我是新建的目录 /usr/local/user)
mkdir -p /usr/local/user
2. 进入目录里下载安装包
进入命令:cd /usr/local/tools
安装命令:wget http://dev.mysql.com/Downloads/MySQL-5.6/MySQL-server-5.6.21-1.rhel5.x86_64.rpm
wget http://dev.mysql.com/Downloads/MySQL-5.6/MySQL-devel-5.6.21-1.rhel5.x86_64.rpm
wget http://dev.mysql.com/Downloads/MySQL-5.6/MySQL-client-5.6.21-1.rhel5.x86_64.rpm
或者
到mysql官方下载所需版本
下载地址: http://dev.mysql.com/downloads/mysql/
下载后安装命令:
rpm -ivh MySQL-server-5.6.21-1.rhel5.x86_64.rpm
rpm -ivh MySQL-client-5.6.21-1.rhel5.x86_64.rpm
rpm -ivh MySQL-devel-5.6.21-1.rhel5.x86_64.rpm
3. 初始化mysql
3.1 修改配置文件到etc目录
cp /usr/local/user/mysql/my-default.cnf /etc/my.cnf
3.2 初始化mysql
/usr/bin/mysql_install_db
3.3 查看mysql服务是否启动
ps -ef|grep mysql
netstat -anpt|grep 3306启动命令:service mysql start
3.4 修改root用户初始密码
查询默认密码:
more /root/.mysql_secret
用初始密码登录:
mysql -uroot -p'初始密码'
修改密码:
set password = password('123456');
退出:exit
重新登陆:
mysql -uroot -p123456
3.5 修改Mysql服务开机时自动启动
chkconfig mysql on
查看设置结果命令:
chkconfig mysql --list
安装完成
4. 一般mysql常用命令
# 检查并且显示Apache相关安装包
[root@localhost ~]# rpm -qa | grep mysql
# 删除MySql
[root@localhost ~]# yum remove -y mysql mysql mysql-server mysql-libs compat-mysql51
或
[root@localhost ~]# rpm -e mysql-community-libs-5.7.20-1.el7.x86_64 --nodeps
或
[root@localhost ~]# yum -y remove mysql-community-libs-5.7.20-1.el7.x86_64
# 查看MySql相关文件
[root@localhost ~]# find / -name mysql
# 重启MySql服务
[root@localhost ~]# service mysqld restart
# 查看MySql版本
[root@localhost ~]# yum repolist all | grep mysql
# 查看当前的启动的 MySQL 版本
[root@localhost ~]# yum repolist enabled | grep mysql
# 通过Yum来安装MySQL,会自动处理MySQL与其他组件的依赖关系
[root@localhost ~]# yum install mysql-community-server
# 查看MySQL安装目录
[root@localhost ~]# whereis mysql
# 启动MySQL服务
[root@localhost ~]# systemctl start mysqld
# 查看MySQL服务状态
[root@localhost ~]# systemctl status mysqld
# 关闭MySQL服务
[root@localhost ~]# systemctl stop mysqld
# 测试MySQL是否安装成功
[root@localhost ~]# mysql
# 查看MySql默认密码
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
# 查看所有数据库
mysql>show databases;
# 退出登录数据库
mysql>exit;
# 查看所有数据库用户
mysql>SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user
本文来自博客园,作者:与乐i,转载请注明原文链接:https://www.cnblogs.com/linanana/p/13445125.html