Linux下使用mysql数据库
这次的安装是基于Linux课程设计实验课下做的,知识来源于课堂的实验指导书(很多安装出现的问题我也不懂为什么,按照步骤我成功了)
1、下载安装包,并传到虚拟机上。
链接:https://pan.baidu.com/s/1_M2AATwIo3q15XUKvCwATw
提取码:2k0m
复制这段内容后打开百度网盘手机App,操作更方便哦
2、解压 mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
[guet@~]# tar -zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
3.切换为root用户并将解压的文件夹重命名为mysql
[guet@~]#sudo su
[root@master soft]# ls
[root@master soft]# mv mysql-5.6.46-linux-glibc2.12-i686/ mysql
4.创建mysql用户组及用户
[root@master soft]# groupadd mysql
[root@master soft]# useradd -r -g mysql mysql
5.将解压的mysql文件夹移动到/usr/local目录下
[root@master soft]# mv mysql/ /usr/local/
6.进入/usr/local/文件夹并修改mysql文件夹用户组及用户为mysql
[root@master soft]# cd /usr/local/
[root@master local]# chown -R mysql:mysql mysql
7.修改/etc/hosts文件夹将IP和主机名添加进去
[root@master scripts]# vi /etc/hosts
192.168.1.110(备注:改为本机IP) master
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
8、为了加快下载的速度,建议更换国内源,百度来的方法https://blog.csdn.net/qq_18724841/article/details/105845921
8.安装依赖包(需保证虚拟机能上网)
[root@master scripts]# apt-get update
[root@master scripts]# apt-get install libnuma1
[root@master scripts]# apt-get install libaio1
9.进入mysql/文件夹,进行安装
[root@master mysql]# ./scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --explicit_defaults_for_timestamp
10.修改data文件及用户组及用户为mysql
[root@master mysql]# chown ‐R mysql:mysql data
11.启动mysql,进入mysql/support-files文件夹执行命令
[root@master mysql]# cd support-files/
[root@master support‐files]# ls
Binary-configure magic my-default.cnf mysqld_multi.server mysql-log-rotate mysql.server
[root@master support‐files]# ./mysql.server start
Starting MySQL.Logging to '/usr/local/mysql/data/master.err'.
SUCCESS!
[root@master support‐files]#
12.修改mysql密码,之前安装时已经提示如何修改(注意new-password是设定的新密码),拷贝数据库头文件,加入数据库库函数到系统中
[root@master bin]# ./mysqladmin -u root password 'new-password'
[root@master bin]# cd ..
[root@master mysql]# cp -rf include/* /usr/local/include/
[root@master mysql]# echo "/usr/local/mysql/lib" >>/etc/ld.so.conf
[root@master mysql]# ldconfig
13.登录mysql
[root@master bin]# ./mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.38 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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>
14.允许远程用户连接
mysql> use mysql;
mysql> SELECT User, Password, Host FROM user;
执行查询,查看数据库当前有访问权限的信息
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
其中"*.*"代表所有资源所有权限, “'root'@%”其中root代表账户名,%代表所有的访问地址,也可以使用一个唯一的地址进行替换,只有一个地址能够访问。如果是某个网段的可以使用地址与%结合的方式,如10.0.42.%。IDENTIFIED BY 'root',这个root是指访问密码。WITH GRANT OPTION允许级联授权。
mysql> FLUSH PRIVILEGES;
刷新访问权限表