发布网友 发布时间:2022-02-26 19:31
共2个回答
懂视网 时间:2022-02-26 23:52
产品型号:Thinkpad E15
系统版本:centos7
软件版本:mysql 5.7
mysql安装教程
1.使用yum安装mysql数据库的软件包
[root@xuegod63 ~]# yum -y install mariadb-server mariadb
注:
mariadb-server #MariaDB数据库
mariadb # MariaDB服务器Linux下客户端
注:从centos7系统开始,系统中自带的mysql数据库变成了mariadb-server,mariadb-server和mysql操作上一样。mariadb-server是mysql的一个分支。
2.启动数据库服务
[root@xuegod63 ~]# systemctl start mariadb #启动MariaDB服务
[root@xuegod63 ~]# systemctl enable mariadb #设置开启自动启动MariaDB服务
3. 安装完mariadb-server后,运行mysql_secure_installation去除安全隐患
[root@xuegod63 ~]# mysql_secure_installation #进入安全配置导向
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): #初次运行直接回车,因为root用户没有密码
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] Y #是否设置root用户密码,输入Y
New password: 123456 #新密码123456
Re-enter new password: 123456
Password updated successfully!
。。。
Remove anonymous users? [Y/n] Y #是否删除匿名用户,生产环境建议删除,所以直接回车或Y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y #是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y #是否删除test数据库,直接回车或Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y #是否重新加载权限表,直接回车
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
… Success!
至此数据库安装成功。
4. 登录数据库
[root@xuegod63 ~]# mysql -u root -p123456
MariaDB [(none)]> show databases; #没有test数据库 #执行时,所有命令以;号结尾
+-------------------------+
| Database |
+-------------------------+
| information_schema |
| mysql |
| ucenter |
+-------------------------+
3 rows in set (0.00 sec)
MariaDB [(none)]> exit #退出命令可以加分号,也可以不加分号。
总结:
1、使用yum安装mysql数据库的软件包
2、启动数据库服务
3、运行mysql_secure_installation去除安全隐患
4、登录数据库
热心网友 时间:2022-02-26 21:00
查找以前是否安装有mysql,使用下面命令:
rpm -qa|grep -i mysql
如果显示有如下包则说明已安装mysql
mysql-4.1.12-3.RHEL4.1
mysqlclient10-3.23.58-4.RHEL4.1
如果已安装,则需要删除已安装的数据库,使用以下命令来删除数据库
删除命令:rpm -e --nodeps 包名
( rpm -ev mysql-4.1.12-3.RHEL4.1 )
删除老版本mysql的开发头文件和库
命令:rm -fr /usr/lib/mysql
rm -fr /usr/include/mysql
注意:卸载后/var/lib/mysql中的数据及/etc/my.cnf不会删除,如果确定没用后就手工删除
rm -f /etc/my.cnf
rm -fr /var/lib/mysql
下载mysql的rpm包
可以通过wget下载具体的地址因为不能用链接请大家去官网去找
(1)MySQL-server-5.6.10-1.rhel5.x86_.rpm:MySQL服务器;
(2)MySQL-client-5.6.10-1.rhel5.x86_.rpm:MySQL客户端;
(3)MySQL-devel-5.6.10-1.rhel5.x86_.rpm:Mysql开发依赖包。
下载后放到Liunx服务器中,如图所示
安装MySQL Server的rpm包
rpm -ivh MySQL-server-5.6.21-1.linux_glibc2.5.x86_.rpm
安装过程如图所示
安装完成后会生成root用户的随机密码,请使用“cat /root/.mysql_secret”或类似命令进行查看。
安装MySQL客户端
rpm -ivh MySQL-client-5.6.21-1.linux_glibc2.5.x86_.rpm
安装MySQL开发依赖包
rpm -ivh MySQL-devel-5.6.21-1.linux_glibc2.5.x86_.rpm
启动msyql
安装完成后mysql是没有启动的,运行mysql命令会提示如下错误:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
可使用如下命令启动MySQL:
service mysql start
或者使用如下命令:
/etc/init.d/mysql start
可使用SET PASSWORD命令修改root用户的密码,参考如下:SET PASSWORD = PASSWORD('root123456');
登录MySQL
使用mysql命令登录MySQL服务器,运行MySQL的命令时,会提示需要设置root用户密码
设置开机自启动
/etc/init.d/mysql start
设置完成后重启系统,使用natstat –nat命令可看到MySQL的3306端口
至此我们已经安装好了mysql数据库,当然现在我们的数据库还不支持远程连接,远程连接会出现以下代码:1130,ERROR 1130: Host 192.168.0.10 is not allowed to connect to this MySQL server,可以通过以下以下来解决
改表法:在本机登入mysql后,更改“mysql”数据库里的“user”表里的“host”项,从”localhost”改为'%'。
mysql>
mysql>use mysql;
mysql>select 'host' from user where user='root';
好了,开始享受mysql带来的强大功能吧