1实验目的CentOS 8 yum安装mariadb-10.3.17并实现三个实例2环境要求一台系统CentOS 8.X主机3前提准备关闭SElinux关闭防火墙时间同步4实现步骤安装 mariadb[root@centos8~]#yum-yinstallmariadb-server准备三个实例的目录[root@centos8~]#mkdir-pv/mysql/{3306,3307,3308}/{data,etc,socket,log,bin,pid}[root@centos8~]#chown-Rmysql.mysql/mysql生成数据库文件[root@centos8~]#mysql_install_db–user=mysql–datadir=/mysql/3306/data[root@centos8~]#mysql_install_db–user=mysql–datadir=/mysql/3307/data[root@centos8~]#mysql_install_db–user=mysql–datadir=/mysql/3308/data准备配置文件[root@centos8~]#vim/mysql/3306/etc/my.cnf[mysqld]port=3306datadir=/mysql/3306/datasocket=/mysql/3306/socket/mysql.socklog-error=/mysql/3306/log/mysql.logpid-file=/mysql/3306/pid/mysql.pid#重复上面步骤设置3307,3308[root@centos8~]#sed’s/3306/3307/’/mysql/3306/etc/my.cnf>/mysql/3307/etc/my.cnf[root@centos8~]#sed’s/3306/3308/’/mysql/3306/etc/my.cnf>/mysql/3308/etc/my.cnf准备启动脚本[root@centos8~]#vim/mysql/3306/bin/mysqld#!/bin/shmysql_user=”root”mysql_pwd=”123456″cmd_path=”/usr/bin”port=3306mysql_basedir=”/mysql”./etc/init.d/functions[$#-ne1]&&{echo”USAGE:{start|stop|restart}”exit1}start(){if[-e${mysql_basedir}/${port}/socket/mysql.sock]thenecho”MySQLisrunning.”else${cmd_path}/mysqld_safe–defaults-file=${mysql_basedir}/${port}/etc/my.cnf&>/dev/null&action”MySQLisstarting”/bin/trueexit0fi}stop(){if[-e${mysql_basedir}/${port}/socket/mysql.sock]then${cmd_path}/mysqladmin-u${mysql_user}-p${mysql_pwd}-S${mysql_basedir}/${port}/socket/mysql.sockshutdown&>/dev/nullaction”MySQLisstoping”/bin/trueelseaction”MySQLisstoping”/bin/falseexit1fi}restart(){stopsleep2start}if[“$1″==”start”]thenstartelif[“$1″==”stop”]thenstopelif[“$1″==”restart”]thenrestartelseecho”USAGE:{start|stop|restart}”fi[root@centos8~]#chmod x/mysql/3306/bin/mysqld#重复上述过程,分别建立3307,3308的启动脚本启动服务[root@centos8~]#/mysql/3306/bin/mysqldstart[root@centos8~]#/mysql/3307/bin/mysqldstart[root@centos8~]#/mysql/3308/bin/mysqldstart[root@centos8~]#ss-ntlStateRecv-QSend-QLocalAddress:PortPeerAddress:PortProcessLISTEN01280.0.0.0:220.0.0.0:*LISTEN080*:3306*:*LISTEN080*:3307*:*LISTEN080*:3308*:*LISTEN0128[::]:22[::]:*登录实例[root@centos8~]#/mysql/3308/bin/mysqldstart#两种连接方法[root@centos8~]#mysql-h127.0.0.1-uroot-P3306[root@centos8~]#mysql-uroot-S/mysqldb/3306/socket/mysql.sock#确认连接的端口MariaDB[(none)]>showvariableslike’port’; ————— ——- |Variable_name|Value| ————— ——- |port|3306| ————— ——- 1rowinset(0.001sec)#关闭数据库,需要手动输入root的密码[root@centos8~]#/mysql/3308/bin/mysqldstopStopingMySQL…Enterpassword:[root@centos8~]#/mysql/3308/bin/mysqldstartStartingMySQL…修改 root 密码#加上root的口令[root@centos8~]#mysqladmin-uroot-S/mysql/3306/socket/mysql.sockpassword’123456′[root@centos8~]#mysqladmin-uroot-S/mysql/3307/socket/mysql.sockpassword’123456′[root@centos8~]#mysqladmin-uroot-S/mysql/3308/socket/mysql.sockpassword’123456’#重复步骤,分别修改别外两个实例3307,3308对应root口令测试连接[root@centos8~]#mysql-uroot-p-S/mysql/3306/socket/mysql.sock#提示输入口令才能登录开机启动[root@centos8~]#echo”foriin{3306..3308};do/mysql/$i/bin/mysqldstart;done”>>/etc/rc.d/rc.local[root@centos8~]#chmod x/etc/rc.d/rc.local5mysql 客户端命令mysql 命令使用格式mysql[OPTIONS][database]
mysql 客户端常用选项:
-A,–no-auto-rehash禁止补全-u,–user=用户名,默认为root-h,–host=服务器主机,默认为localhost-p,–passowrd=用户密码,建议使用-p,默认为空密码-P,–port=服务器端口-S,–socket=指定连接socket文件路径-D,–database=指定默认数据库-C,–compress启用压缩-e”SQL”执行SQL命令-V,–version显示版本-v–verbose显示详细信息–print-defaults获取程序默认使用的配置安装 mycli
MyCLI 是 MySQL,MariaDB 和 Percona 的命令行界面,具有自动完成和语法突出显示功能
##安装依赖包[root@centos8~]#yuminstall-yepel-releasezlib-develbzip2-developenssl-develncurses-develsqlite-develreadline-develtk-devellibffi-develgccmake##下载Python3.8安装包[root@centos8~]#wgethttps://www.python.org/ftp/python/3.8.0/Python-3.8.0b3.tgz#解压安装包[root@centos8~]#tar-xfPython-3.8.0b3.tgz#进入Python目录,指定安装目录并编译安装[root@centos8~]#cdPython-3.8.0b3[root@centos8Python-3.8.0b3]#./configure–prefix=/app/python/python3.8[root@centos8Python-3.8.0b3]#make&&makeinstall#创建python3.8和pip3.8的软连接[root@centos8~]#ln-s/app/python/python3.8/bin/python3.8/usr/bin/python3.8[root@centos8~]#ln-s/app/python/python3.8/bin/pip3.8/usr/bin/pip3.8#升级pip包管理器版本至最新版,安装Mycli[root@centos8~]#pip3.8install–upgradepip[root@centos8~]#pip3.8install–ignore-installedmycli#Mycli所在目录[root@centos8~]#cd/app/python/python3.8/bin/#追加环境变量,注意要使用单引号[root@centos8bin]#echo-e’PATH=$PATH:/app/python/python3.8/bin/\nexportPATH’>>/etc/profile#生效环境变量[root@centos8bin]#source/etc/profile#启动方法[root@centos8bin]#./mycli-urootPassword:##至此安装全部完成