一、安装
1、去官网查看最新安装包
https://dev.mysql.com/downloads/repo/yum/
2、进行mysql的安装
可以通过# yum list | grep mysql命令查看yum上提供的MySQL数据库可下载的版本。
[root@izbp12ujq5zpxyjm1g69dhz ~]# yum list | grep mysql
可以看到yum服务器上MySQL的可以下载的版本信息:
[root@izbp12ujq5zpxyjm1g69dhz ~]# yun list | grep mysql
-bash: yun: command not found
[root@izbp12ujq5zpxyjm1g69dhz ~]# yum list | grep mysql
akonadi-mysql.x86_64 1.9.2-4.el7 base
apr-util-mysql.x86_64 1.5.2-6.el7 base
calligra-kexi-driver-mysql.x86_64 2.9.10-2.el7 epel
collectd-mysql.x86_64 5.8.1-1.el7 epel
dmlite-plugins-mysql.x86_64 1.13.2-2.el7 epel
dovecot-mysql.x86_64 1:2.2.36-3.el7_7.1 updates
dpm-copy-server-mysql.x86_64 1.13.0-1.el7 epel
dpm-name-server-mysql.x86_64 1.13.0-1.el7 epel
dpm-server-mysql.x86_64 1.13.0-1.el7 epel
dpm-srm-server-mysql.x86_64 1.13.0-1.el7 epel
dspam-mysql.x86_64 3.10.2-12.el7 epel
exim-mysql.x86_64 4.92.3-1.el7 epel
freeradius-mysql.x86_64 3.0.13-10.el7_6 base
fts-mysql.x86_64 3.8.4-2.el7 epel
gnokii-smsd-mysql.x86_64 0.6.31-17.el7 epel
holland-mysql.noarch 1.1.18-1.el7 epel
holland-mysqldump.noarch 1.1.18-1.el7 epel
holland-mysqllvm.noarch 1.1.18-1.el7 epel
lfc-server-mysql.x86_64 1.13.0-1.el7 epel
libdbi-dbd-mysql.x86_64 0.8.3-16.el7 base
libgda-mysql.x86_64 1:5.2.2-7.el7 epel
libnss-mysql.x86_64 1.5-19.el7 epel
libodb-mysql.x86_64 2.3.0-1.el7 epel
libodb-mysql-devel.x86_64 2.3.0-1.el7 epel
lighttpd-mod_authn_mysql.x86_64 1.4.54-1.el7 epel
lighttpd-mod_mysql_vhost.x86_64 1.4.54-1.el7 epel
mysql++.x86_64 3.1.0-12.el7 epel
mysql++-devel.x86_64 3.1.0-12.el7 epel
mysql++-manuals.x86_64 3.1.0-12.el7 epel
mysql-connector-java.noarch 1:5.1.25-3.el7 base
mysql-connector-odbc.x86_64 5.2.5-8.el7 base
mysql-connector-python.noarch 1.1.6-1.el7 epel
mysql-mmm.noarch 2.2.1-15.el7 epel
mysql-mmm-agent.noarch 2.2.1-15.el7 epel
mysql-mmm-monitor.noarch 2.2.1-15.el7 epel
mysql-mmm-tools.noarch 2.2.1-15.el7 epel
mysql-proxy.x86_64 0.8.5-2.el7 epel
mysql-proxy-devel.x86_64 0.8.5-2.el7 epel
通过yum install -y mysql-server mysql mysql-devel命令进行安装
[root@izbp12ujq5zpxyjm1g69dhz ~]# yum install -y mysql-server mysql mysql-devel
3、mysql数据库的初始化及相关配置
1、MySQL的启动(如果我们是第一次启动mysql服务,mysql服务器首先会进行初始化的配置)
[root@izbp12ujq5zpxyjm1g69dhz ~]# service mysqld start
[root@izbp12ujq5zpxyjm1g69dhz ~]# service mysqld start
初始化 MySQL 数据库: WARNING: The host 'xiaoluo' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h xiaoluo password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script![确定]
正在启动 mysqld: [确定]
2、这时我们会看到第一次启动mysql服务器以后会提示非常多的信息,目的就是对mysql数据库进行初始化操作。然后我们重新启动后mysql
[root@izbp12ujq5zpxyjm1g69dhz ~]# service mysqld restart
停止 mysqld: [确定]
正在启动 mysqld: [确定]
3、MySQL并没有开机开机自动启动,我们当然可以通过 chkconfig mysqld on 命令来将其设置成开机启动,这样就不用每次都去手动启动了
[root@izbp12ujq5zpxyjm1g69dhz ~]# chkconfig mysqld on
[root@izbp12ujq5zpxyjm1g69dhz ~]# chkconfig --list | grep mysql
mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
4、MySQL数据库安装完以后只会有一个root管理员账号,但是此时的root账号还并没有为其设置密码,在第一次启动MySQL服务时,会进行数据库的一些初始化工作,所以我们可以通过 该命令来给我们的root账号设置密码。
为root账号设置密码
/usr/bin/mysqladmin -u root password 'new-password'
通过该命令给root账号设置密码为 root
[root@izbp12ujq5zpxyjm1g69dhz ~]# mysqladmin -u root password 'root'
5、这时我们就可以通过 mysql -u root -p 命令来登录我们的mysql数据库了
[root@izbp12ujq5zpxyjm1g69dhz ~]mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql>
二、修改root密码的4种方法
方法1: 用SET PASSWORD命令
mysql -u root
mysql> SET PASSWORD FOR ‘root’@‘localhost’ = PASSWORD(‘newpass’);
方法2:用mysqladmin
mysqladmin -u root password “newpass”
如果root已经设置过密码,采用如下方法
mysqladmin -u root password oldpass “newpass”
方法,3: 用UPDATE直接编辑user表
mysql -u root
mysql> use mysql;
mysql> UPDATE user SET Password = PASSWORD(‘newpass’) WHERE user = ‘root’;
mysql> FLUSH PRIVILEGES;
方法4,在丢失root密码的时候,可以这样
mysqld_safe --skip-grant-tables&
mysql -u root mysql
mysql> UPDATE user SET password=PASSWORD(“new password”) WHERE user=‘root’;
mysql> FLUSH PRIVILEGES;。
三、MySQL的备份与还原
MySQL备份和还原,都是利用mysqldump、mysql和source命令来完成的。
1.Win32下MySQL的备份与还原
1.1 备份
开始菜单 | 运行 | cmd |利用“cd /Program Files/MySQL/MySQL Server 5.0/bin”命令进入bin文件夹 | 利用“mysqldump -u 用户名 -p databasename >exportfilename”导出数据库到文件,如mysqldump -u root -p voice>voice.sql,然后输入密码即可开始导出。
1.2 还原
进入MySQL Command Line Client,输入密码,进入到“mysql>”,输入命令"show databases;",回车,看看有些什么数据库;建立你要还原的数据库,输入"create database voice;",回车;切换到刚建立的数据库,输入"use voice;",回车;导入数据,输入"source voice.sql;",回车,开始导入,再次出现"mysql>"并且没有提示错误即还原成功。