目录
配置mysql 外部访问
mysql启动时报错:error while loading shared libraries: libncurses.so.5: cannot open shared object file
mysql主从搭建
配置mysql 外部访问
(1).确保MySQL服务正在运行:
sudo systemctl start mysqld sudo systemctl enable mysqld(2).允许远程连接:编辑MySQL配置文件my.cnf(通常位于/etc/my.cnf),在[mysqld]部分添加以下行:
bind-address = 0.0.0.0 ## 或者,如果你想仅允许特定IP的连接,可以替换0.0.0.0为那个特定的IP地址。(3).为远程用户授权:
GRANT ALL PRIVILEGES ON *.* TO 'yourusername'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION; FLUSH PRIVILEGES; #替换yourusername和yourpassword为实际的用户名和密码。(4).确保CentOS防火墙允许外部连接到MySQL的端口(默认为3306):
sudo firewall-cmd --permanent --zone=public --add-service=mysql sudo firewall-cmd --reload5.重新启动MySQL服务以应用更改:
sudo systemctl restart mysqldmysql启动时报错:error while loading shared libraries: libncurses.so.5: cannot open shared object file
登录mysql,报错
mysql -uroot -p ./mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory解决:
1)使用find命令查找本机的libncurses文件
find / -name "libncurses*" /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.6.1 /usr/lib64/libncursesw.so.6 /usr/lib64/libncursesw.so.6.1 /usr/lib64/libncurses++.so.6 /usr/lib64/libncurses++.so.6.1 /usr/lib64/libncurses++w.so.6 /usr/lib64/libncurses++w.so.6.1 /usr/lib64/libncurses++.so /usr/lib64/libncurses++w.so /usr/lib64/libncurses.so /usr/lib64/libncursesw.so ##根据上面显示内容,没有对应的libncurses.so.5文件,这个时候可以将高版本创建软连接到5版本2) 将高版本libncurses.so.6创建软连接到libncurses.so.5版本
ln -s /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.53)如果未找到 libncurses.so 相关的文件则安装它
yum install libncurses* -y登录msyql 报error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
mysql -uroot -p error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory解决:
1)使用find命令查找本机的libtinfo.so文件
find / -name "libtinfo*" /usr/lib64/libtinfo.so.6 /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so2) 将高版本libtinfo.so.6创建软连接到libtinfo.so.5版本
ln /usr/lib64/libtinfo.so.6 /usr/lib64/libtinfo.so.5再次启动成功
mysql主从搭建
1、在主库上创建一个有权限的用户,用于从库登录主库进行复制
# 在主库上: create user 'repl'@'192.168.137.%' identified with mysql_native_password by 'Repl@001'; grant replication slave on *.* to 'repl'@'192.168.137.%'; flush privileges; # 查看主库日志名称和读写位置 show master status; +--------------------+----------+--------------+-------------------------------------------------+------------------------------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +--------------------+----------+--------------+-------------------------------------------------+------------------------------------------+ | mysql-bin-A.000002 | 2053 | | mysql,information_schema,performance_schema,sys | 34bfd5a9-0dae-11ef-ad2d-00155d24fe02:1-8 | +--------------------+----------+--------------+-------------------------------------------------+------------------------------------------+2、配置从库的用户信息
# 配置主库地址,账号,日志名,位置 change master to master_host='192.168.137.8',master_user='repl',master_password='Repl@001',master_log_file='mysql-bin-A.000002',master_log_pos=2053,get_master_public_key=1; # 启动主从同步 start slave; # 查看主从同步状态,两个yes,文件名和主库一致,然后数据位置一样即可 show slave status;