当前位置: > 其它学习 > 日常运维 >

mysql安装

时间:2019-02-11 15:49来源:www.it.net.cn 作者:IT网
mysql -v
 
 
 
 
--------------------------------------------------
 
 
安装
yum -y install mysql-community-server
 
 
yum
 
安装server:
 
yum install mysql-community-server
 
yum
安装client:
 
yum install mysql-community-client
 
 
 
卸载
yum remove mysql mysql-server mysql-libs 
 
 
--------------------------------------------------
 
 
 
 
 
启动mysql服务:systemctl start mysqld
 
使用命令查看mysql状态:systemctl status mysqld
 
 
mysq服务加入开机启动(可选):systemctl enable mysqld
 
 
查询日志文件得到密码:grep "password" /var/log/mysqld.log
 
mysql -r root -p
 
 
输入日志文件查找的密码,注意,第一次登陆比如重置root密码,
 
执行一下命令
 
set password for root@localhost = password('itnetcn');
 
 
数据库外网不能连接
mysql -u root -p
 
use mysql
select host from user where user='root';
产看root用户连接权限
 
+-----------+
| host      |
+-----------+
| localhost |
+-----------+
1 row in set (0.00 sec)
 
 
 update user set host = '%' where user ='root'
 
systemcel restart mysqld

 
-----------------------------------------------------------------




CentOS7的yum源中默认好像是没有mysql的。为了解决这个问题,我们要先下载mysql的repo源。

1. 下载mysql的repo源



$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
2. 安装mysql-community-release-el7-5.noarch.rpm包



$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
安装这个包后,会获得两个mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo。

3. 安装mysql



$ sudo yum install mysql-server
根据步骤安装就可以了,不过安装完成后,没有密码,需要重置密码。

4. 重置密码

修改MySQL的登录设置:
# vim /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables
例如:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
保存并且退出vi。

重新启动mysqld
# service mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]

登录并修改MySQL的root密码
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 3.23.56
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql> USE mysql ;
Database changed
mysql> UPDATE user SET Password = password ( ‘new-password’ ) WHERE User = ‘root’ ;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0
mysql> flush privileges ;
Query OK, 0 rows affected (0.01 sec)
mysql> quit

将MySQL的登录设置修改回来
# vim /etc/my.cnf
将刚才在[mysqld]的段中加上的skip-grant-tables删除
保存并且退出vim

重新启动mysqld
# service mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]

方式二:

# step1:卸载

[root@linux.it.net.cn ~]# rpm -qa | grep mysql

mysql-5.1.73-3.el6_5.x86_64

mysql-libs-5.1.73-3.el6_5.x86_64

mysql-server-5.1.73-3.el6_5.x86_64

[root@linux.it.net.cn ~]# rpm -e --nodeps mysql-5.1.73-3.el6_5.x86_64 mysql-libs-5.1.73-3.el6_5.x86_64 mysql-server-5.1.73-3.el6_5.x86_64





# step2: 下载yum包,导入本地

[root@linux.it.net.cn ~]# yum localinstall /usr/local/src/mysql-community-release-el6-5.noarch.rpm





# step3:安装

[root@linux.it.net.cn ~]# yum install mysql-community-server





# step4:启动

[root@linux.it.net.cn ~]# service mysqld start





# step5:开机启动

[root@linux.it.net.cn ~]# chkconfig --list | grep mysqld

mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off

[root@linux.it.net.cn ~]# chkconfig mysqld on





# step6:设置本地登录密码

[root@linux.it.net.cn ~]# mysqladmin -uroot -p password 123456





# step7:设置远程登录密码

[root@linux.it.net.cn ~]# mysql -uroot -p123456

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

mysql> flush privileges;


-------------------------------------------------------------------------------------------------------

第1步、yum安装mysql
[root@linux.it.net.cn ~]#  yum -y install mysql-server
安装结果:
Installed:
    mysql-server.x86_64 0:5.1.73-3.el6_5                                                                                                                                                        
Dependency Installed:
    mysql.x86_64 0:5.1.73-3.el6_5                                perl-DBD-MySQL.x86_64 0:4.013-3.el6                                perl-DBI.x86_64 0:1.609-4.el6

第2步、设置开机启动
[root@linux.it.net.cn ~]#  chkconfig mysqld on

第3步、启动MySql服务
[root@linux.it.net.cn ~]#  service mysqld start

第4步、设置MySQL的root用户设置密码
[root@linux.it.net.cn ~]#  mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
...... 省略了一些行


mysql> select user,host,password from mysql.user;

查询用户的密码,都为空,用下面的命令设置root的密码为itnetcn

mysql> set password for root@localhost=password('itnetcn');
mysql> exit

第5步、用新密码登陆
[root@linux.it.net.cn ~]#  mysql -u root -p

第6步、基本命令
show databases; //查看系统已存在的数据库
use databasesname;   //选择需要使用的数据库
drop database databasename; //删除选定的数据库
exit    //退出数据库的连接
create database test01;    //建立名为test的数据库
show tables;        // 列出当前数据库下的表
其他基本的增删改查使用标准SQL即可

第7步、开放远程登录权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
FLUSH PRIVILEGES;
 
 

(责任编辑:IT)
------分隔线----------------------------