安装mysql服务
sudo apt-get install mysql-server
安装当中,会提示输入root账户的密码,按提示输入即可,安装后默认开启了server。
安装mysql客户端
sudo apt-get isntall mysql-client
安装mysql的c语言开发接口
sudo apt-get install libmysqlclient-dev
开启、关闭、重启
启动: /etc/inint.d/mysqld start
停止: /etc/inint.d/mysqld stop
重启: /etc/inint.d/mysqld restart
首先去下载rpm安装包:https://dev.mysql.com/downloa…,选择红帽linux64位带bundle结尾的版本。
安装新版mysql之前,我们需要将系统自带的mariadb-lib卸载
rpm -qa | grep mariadb
yum remove mariadb*
到mysql的官网下载最新版mysql的rpm集合包:mysql-xx.rpm-bundle.tar, 其中最简单的安装mysql-server服务,只需要安装如下4个软件包即可,我们可以使用rpm -ivh命令进行安装。
安装顺序(一步一步来):
1、rpm -ivh mysql-community-common-5.7.9-1.el7.x86_64.rpm
2、rpm -ivh mysql-community-libs-5.7.9-1.el7.x86_64.rpm --(依赖于 common)
3、rpm -ivh mysql-community-client-5.7.9-1.el7.x86_64.rpm --(依赖于libs)
4、rpm -ivh mysql-community-server-5.7.9-1.el7.x86_64.rpm --(依赖于client、common )
如果报以下错误,表示缺失libnuma依赖包,使用yum进行安装
libnuma.so.1()(64bit) is needed by MySQL-server-5.6.27-1.el6.x86_64
libnuma.so.1(libnuma_1.1)(64bit) is needed by MySQL-server-5.6.27-1.el6.x86_64
libnuma.so.1(libnuma_1.2)(64bit) is needed by MySQL-server-5.6.27-1.el6.x86_64
下载地址:
http://mirror.centos.org/centos/6/os/x86_64/Packages/numactl-2.0.9-2.el6.x86_64.rpm
如果报以下错误,表示缺失libaio依赖包,使用yum进行安装
error: Failed dependencies:
libaio.so.1()(64bit) is needed by mysql-community-server-5.7.20-1.el7.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.20-1.el7.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.20-1.el7.x86_64
缺失其他就用yum对应安装就好
到此,安装完成。然后我们进行初始化数据库,因为我是root安装的所以想要指定一个mysql用,用mysql启动。根据自己的需要也可以不加。初始化:
mysqld --initialize --user=mysql
此方法,执行生会在/var/log/mysqld.log生成随机密码,使用grep命令过滤查看
grep 'temporary password' /var/log/mysqld.log
2017-11-17T08:05:05.411354Z 1 [Note] A temporary password is generated for root@localhost: Ret6HK7sab
启动:systemctl start mysqld
停止:systemctl stop mysqld
重启:systemctl restart mysqld
设置开机自动启动并查看是否设置成功:
systemctl enable mysqld
systemctl is-enabled mysqld
返回 enabled
初始用密码登陆数据库,需要修改账号密码
set password for 'root'@'localhost'=password('123456');
默认情况下,mysql只允许本地登录,如果要开启远程连接,则需要修改/etc/mysql/my.conf文件
修改 /etc/my.conf 文件
找到 bind-address = 127.0.0.1 这一行注释掉
重启mysql:systemctl restart mysqld 或 /etc/inint.d/mysqld restart
创建用户,作权限分配,给用户指定某个数据库的操作权限
create user 'username'@'host' identified by 'password';
GRANT ALL PRIVILEGES ON dbname.* to 'username'@'%';
flush privileges
注意:“dbname.*” 解析:dbname为数据库名称,*代表全部权限,’username’@’%’ 解析:% 表示任意的ip或域名。
ps: 特别提醒注意的一点是,新版的mysql数据库下的user表中已经没有 Password字段了,而是将加密后的用户密码存储于authentication_string字段