MySql教程

Linux安装mysql(CentOS6)

本文主要是介绍Linux安装mysql(CentOS6),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

使用tar.gz安装

1.删除旧的,操作如上
2.下载mysql对应安装包
官网下载:历史版本下载
下载好后通过xftp上传至虚拟机

 

3.安装和配置
MySQL依赖libaio库

[root@localhost ~]# yum install libaio

4.创建mysql用户
不需要登录的一个系统账号,启动MySQL服务时会使用该账号

[root@localhost mysql]# groupadd mysql
[root@localhost mysql]# useradd -r -g mysql -s /bin/false mysql

5.解压并创建链接

[root@localhost mysql]# tar zxvf /root/mysql/mysql-8.0.15-linux-glibc2.12-i686.tar.gz
或者
[root@localhost mysql]# tar -xvf /root/mysql/mysql-8.0.15-linux-glibc2.12-i686.tar
或者
[root@localhost mysql]# tar -xvJf /root/mysql/mysql-8.0.15-linux-glibc2.12-i686.tar.xz
修改文件名
[root@localhost mysql]# mv mysql-8.0.15-linux-glibc2.12-i686 mysql 
将文件移动到/usr/local/
[root@localhost mysql]# cp mysql-8.0.15-linux-glibc2.12-i686.tar.xz /usr/local/

6.修改/usr/local/mysql 目录为mysql用户

cd /usr/local/mysql //进入/usr/local/mysql 目录

[root@localhost mysql]# cd /usr/local/mysql //进入/usr/local/mysql 目录
[root@localhost mysql]# chown -R mysql:mysql ./

7.mysql初始化操作

[root@localhost mysql]# ./bin/mysqld  --initialize  --user=mysql  --basedir=/usr/local/mysql  --datadir=/usr/local/mysql/data
./bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
# 初始化报错,请执行以下命令,查看是否安装齐全
yum search libaio
yum install libaio
yum -y install numactl
yum install libnuma
yum install ld-linux.so.2
yum install libaio.so.1
yum install libnuma.so.1
yum install libstdc++.so.6
yum install libtinfo.so.5

 

 

 8.启动服务

[root@localhost mysql]# cd support-files
[root@localhost support-files]# ./mysql.server start
Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
.. SUCCESS! 

success表示已经启动成功

9.配置mysql环境

[root@localhost ~]# vi /etc/profile

xport MYSQL_HOME=/usr/local/mysql
export MYSQL_PATH=${MYSQL_HOME}/bin:${MYSQL_HOME}/lib
export PATH=$PATH:/usr/local/mysql/bin

 

 

 

shutdown -r now 重启下服务器或者 source /etc/profile 均可使环境变量生效

10.系统配置

cp /usr/local/mysql/support-files/mysql.server   /etc/init.d/mysql   //拷贝mysql.server 
 
chmod +x  /etc/init.d/mysql           //添加可执行权限。
 
chkconfig  --add mysql               // 注册启动服务
chkconfig  --list   //查看是否添加成功

 

 

 

至此mysql就安装成功了

11.修改初始密码

[root@localhost ~]# mysql -uroot -p
Enter password:        //这里输入刚刚初始化操作时的初始密码

mysql> alter user 'root'@'localhost' identified by '你的新密码';
Query OK, 0 rows affected (0.02 sec)

mysql>use mysql
#设置允许远程登录
mysql> update user set user.Host='%' where user.User='root';

 

12.关闭防火墙
允许远程登录

 

 

 

13即可通过mysql客户端远程登陆

 

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;//更改用户 myuser 的密码 为 123456
service mysql stop//停止mysql服务
service mysql start//启动mysql服务
service mysql restart//重启mysql服务
 flush privileges;//刷新权限表,使密码修改等操作即时生效、重启mysql服务也可以

 

安装mysql参考博客

https://blog.csdn.net/qq_41510551/article/details/110731610

 

执行yum install libaio 若报错信息如下所示

已加载插件:fastestmirror, refresh-packagekit, security
设置安装进程
Loading mirror speeds from cached hostfile
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
 Eg. Invalid release/repo/arch combination/
removing mirrorlist with no valid mirrors: /var/cache/yum/x86_64/6/base/mirrorlist.txt
错误:Cannot find a valid baseurl for repo: base

https://www.cnblogs.com/pistachio123/p/14301949.html

 

https://blog.csdn.net/qq_51313111/article/details/116330664

https://blog.csdn.net/yuanhong55/article/details/75000208

这篇关于Linux安装mysql(CentOS6)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!