Linux安装Mysql,Centos7安装Mysql5.5,Linux Mysql安装
Linux安装Mysql,Centos7安装Mysql5.5,Linux Mysql安装
================================
©Copyright 蕃薯耀 2020-11-03
https://www.cnblogs.com/fanshuyao/
一、检查是否安装了mariadb:
rpm -qa | grep mariadb
二、删除mariadb(如果存在则删除,没则跳过)
yum -y remove mariadb-libs-5.5.56-2.el7.x86_64
三、解压Mysql(预先上传mysql安装包:mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz,放在/java目录)
cd /java
tar -zxvf mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz
四、解压后,修改文件夹的名称,简单易记
mv mysql-5.5.62-linux-glibc2.12-x86_64 mysql5.5
五、在/usr/local/目录下创建到/java/mysql5.5的软链接(为什么创建软链接:因为/etc/rc.d/init.d/mysqld配置的路径是/usr/local/mysql)
cd /usr/local
ln -s /java/mysql5.5 mysql
六、添加mysql用户,修改mysql目录权限,并用此用户执行应用
useradd -s /bin/false -M mysql cd /java chown -R mysql:mysql mysql5.5
七、安装mysql,进入mysql目录执行以下命令
cd /java/mysql5.5/
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
安装后,有提示修改密码(但必须先启动mysql),可以略过:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h host_132.11 password 'new-password'
八、复制配置文件:
cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
九、修改配置文件(/etc/my.cnf)
vim /etc/my.cnf
十、配置文件的内容
[client] default-character-set =utf8mb4 socket=/usr/local/mysql/mysql.sock [mysqld] # MySQL服务端默认监听的TCP/IP端口 port = 3306 # 设置默认存储引擎为InnoDB default-storage-engine=InnoDB # MySQL服务端字符集 character-set-server=utf8mb4 # MySQL服务端字符集 collation_server = utf8mb4_general_ci # 库名、表名是否区分大小写。默认为0,设置1,不区分大小写,创建的表、数据库都以小写形式存放磁盘。 lower_case_table_names=1 # MySQL软件安装路径 basedir=/usr/local/mysql # MySQL数据文件存放路径 datadir=/usr/local/mysql/data # 用于本地连接的Unix套接字文件存放路径 socket=/usr/local/mysql/mysql.sock [mysql] default-character-set=utf8mb4 socket=/usr/local/mysql/mysql.sock [mysqld_safe] log-error=/usr/local/mysql/mysql-error.log pid-file=/usr/local/mysql/mysqld.pid
十一、设置mysql自启动。拷贝启动程序,将mysql的启动程序拷贝到/etc/init.d/目录下
复制文件:
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
设置开机启动:
/sbin/chkconfig mysqld on
显示自启动服务列表:
chkconfig --list
十二、安装完,启动mysql服务
service mysqld start
十三、配置环境变量,编辑/etc/profile,方便在任何地方用mysql命令
vim /etc/profile
#修改的内容
#增加mysql变量配置 JAVA_HOME=/java/jdk1.8 MYSQL_HOME=/usr/local/mysql PATH=$JAVA_HOME/bin:$MYSQL_HOME/bin:$PATH CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JAVA_HOME MYSQL_HOME PATH CLASSPATH 重新编译,让配置生效 source /etc/profile
十四、开放Mysql端口:
开放端口: firewall-cmd --zone=public --add-port=3306/tcp --permanent 让端口生效: firewall-cmd --reload 查看防火墙所有开放的端口 firewall-cmd --zone=public --list-ports
十五、进入mysql(提示输入密码时,直接回车)
mysql -uroot -p
十六、修改mysql root用户密码
要选择一个数据库: use mysql; 修改密码: set password=password('root'); 刷新权限: flush privileges;
十七、至此本机登录密码修改完成,若是想让其他机器访问,需要配置远程访问:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
十八、退出mysql
quit;
十九、其它命令:
# Mysql启动关闭常用命令 # 启动 service mysqld start # 关闭 service mysqld stop # 重启 service mysqld restart # 查看运行状态 service mysqld status # 启动 systemctl start mysqld # 查看状态 systemctl status mysqld # 设置为开机自启 /sbin/chkconfig mysqld on # 禁止开机自启 systemctl disable mysqld # 安装lrzsz,用来上传文件: yum install -y lrzsz
================================
©Copyright 蕃薯耀 2020-11-03
https://www.cnblogs.com/fanshuyao/