Debian编译安装Mysql 5.5
安装依赖
apt install -y binutils wget tar build-essential cmake gcc gawk bison flex texinfo automake autoconf libtool cvs libncurses5-dev libglib2.0-dev gettext intltool subversion
下载mysql并解压
# 官网下载mysql5.5.62
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.5.62.zip
# 解压
tar -zxf mysql-5.5.62.tar.gz
# 进入目录
cd mysql-5.5.62
设置用户和权限组
# 创建用户组
groupadd mysql
# 用户组创建用户
useradd -M -s/sbin/nologin -g mysql -r mysql
设置编译参数并安装
# 设置编译参数
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/home/mysql/data -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_unicode_ci -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_DEBUG=0 -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql
# 编译并安装
make&&make install
授权mysql目录运行用户
chown -R mysql:mysql /usr/local/mysql
mkdir -p /home/mysql/data
chown -R mysql:mysql /home/mysql
配置my.cnf文件
rm -rf /etc/my.cnf
touch /etc/my.cnf
vim /etc/my.cnf
复制粘贴下面的参数,也可以自己自定义!!
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /home/mysql/data
socket = /tmp/mysql.sock
log-error = /home/mysql/data/error.log
max_connections = 500
thread_cache_size = 10
default-storage-engine = MyISAM
innodb = OFF
skip-innodb
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 20M
table_open_cache = 256
table_definition_cache = 400
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log-bin = mysql-bin
binlog_format = mixed
server-id = 1
[mysqldump]
quick
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
初始化mysql
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/home/mysql/data/ --defaults-file=/etc/my.cnf
chmod 775 /usr/local/mysql/support-files/mysql.server
/usr/local/mysql/support-files/mysql.server start
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/mysqladmin
ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump
ln -s /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk
ln -s /usr/local/mysql/bin/mysqld_safe /usr/bin/mysqld_safe
rm -rf /usr/local/mysql/data/test
创建开机自启动
touch /lib/systemd/system/mysql.service
vim /lib/systemd/system/mysql.service
保存以下文本
[Unit]
Description=mysql server Service
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecReload=/usr/local/mysql/support-files/mysql.server restart
ExecStop=/usr/local/mysql/support-files/mysql.server stop
[Install]
WantedBy=multi-user.target
创建软连接
ln -s /lib/systemd/system/mysql.service /etc/systemd/system/multi-user.target.wants/mysql
systemctl daemon-reload
systemctl enable mysql
设置root密码
由于刚刚安装好的mysql默认密码为空,为了安全起见,安装完成后进行修改密码。
mysql -u root -p
nter password:
# 密码为空,直接回车
mysql> SET PASSWORD = PASSWORD('123456');
这样就成功修改成了默认密码为123456。
网站教程,网站源码,日常生活,美化教程 2024-06-05 10:31:43 通过 网页 浏览(146)
共有0条评论!