È»ºó¾ÍÊÇ°²×°Ö±µ½Íê³É.
µ«Êǵ±ÎÒÆô¶¯mysql·þÎñʱ service mysql start¸æËßÎÒûÓÐÕâ¸ö·þÎñ,ÕâÔõô¿ÉÄÜ,ÎÒ¸Õ¸Õ×°µÄÎÒcdµ½init.dÏÂÃæ cd/etc/init.d
lsһϷ¢ÏÖȷʵûÓÐmysqlÆô¶¯½Å±¾,ÕâÊÇÔõô»ØÊÂ,ºóÀ´¾¹ý¶à·½Á˽â,ÓÖÈ¥¹Ù·½ÍøÕ¾ÉÏ¿´ÁË,"ÓÐÒ»ÖÖÐèÒª½ÐËûÃÇÈÏΪÄã²»ÐèÒª",ÔÀ´ÊÇ´Óubuntu16¿ªÊ¼²»ÓÃÒÔÇ°µÄserviceÁ˸ÄÓÃsystemctlÁË,ÕâÑùµÄ»°µÃ×°systemd¿ÉÎÒÓÖ²»Ïë×°,ûÓÐÄǾ͵ÃÏë°ì·¨,ÎÒÖØн¨Á˸öÈÝÆ÷×°ÁËmysql5.7°ÑÀïÃæµÄmysql½Å±¾Ìá³öÀ´·Åµ½init.dÀï,Æô¶¯·¢ÏÖ²»ÐÐ,Ìáʾ»µµÄ.ºóÀ´ÓÖÈ¥¹Ù·½ÕÒ,¿´µ½¹Ù·½µÄmysql8ÓÐÒ»ÖÖ¶þ½øÖÆ°²×°°ü,ÎÒ°ÑËüÏÂÔØÏÂÀ´,ËüÖ»Ðè°Ñ°²×°°üµÄÎļþ¸´ÖƵ½/usr/localÏÂÃæ¾Í¿ÉÔËÐÐ,ÎÒ°ÑËüµÄÆô¶¯½Å±¾¿½±´³öÀ´,ÓÃnotepad++´ò¿ª°´ÕÕµÄmysql8µÄ°²×°Ä¿Â¼¸ÄÁËϸ´ÖƵ½init.dÏÂ,¼ÓÖ´ÐÐȨÏÞ,chmod +x mysqlºóservice mysql startÖÕÓÚÔËÐÐÆðÀ´ÁË.¾Í¸ÄÒ²ÏÂÃæÕ⼸Ïî
mysql -uroot --skip-password <<EOF
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "$MYSQL_ROOT_PASSWORD";
create user 'root'@'%' identified by "$MYSQL_ROOT_PASSWORD";
grant all privileges on *.* to 'root'@'%' with grant option;
FLUSH PRIVILEGES;
quit
EOF
echo "MYSQL³õʼ»¯Íê³É,ÕýÔÚдÈë±êÖ¾Îļþ"
touch /var/lib/mysql/initialized
echo "ÕýÔڹرÕMYSQL·þÎñÆ÷"
service mysql stop
fi
echo "ÕýÔڹرÕMYSQL·þÎñÆ÷"
service mysql stop
echo "ÕýÔÚÆô¶¯ÍøÒ³·þÎñÆ÷"
service apache2 start
#Æô¶¯ Mysql ·þÎñÆ÷
service mysql start
echo "MYSQL+apache+phpÆô¶¯Íê³É,AMP»·¾³´î½¨Íê³É,¿ÉÒÔʹÓÃÁË"
tail -f /dev/null
Õâ´ÎÎÒ²»docker exec½øÈ¥ÁË£¬ÎҾͿ´ÈÕÖ¾ÁË,·¢ÏÖµÚ¶þ´Î²¢Ã»Óгõʼ»¯,ÏÔʾ"MYSQL+apache+phpÆô¶¯Íê³É,AMP»·¾³´î½¨Íê³É,¿ÉÒÔʹÓÃÁË"
ÎҲŽøÈ¥¿´,·¢ÏÖapache2»¹ÊDz»¼ûÁË,ÄѵÀdockerÖ»ÄÜÆô¶¯Ò»¸ö·þÎñ,²»¶Ô°¡,ÎÒÔÚÀïÃæÔÙservice apache2 startÊÇ¿ÉÒԵİ¡,¶øÇÒÒ²ÓÐÈË×öÁËapache2+mysql8µÄ¾µÏñµÄ°¡,ÓÚÊÇÔٴθĶ¯,ÎÒ°Ñapache2ÒƵ½½Å±¾¶¥ÉÏ,ÓÖ¼ÓÁËÁ½Ãë͢ʱ,ÐÞ¸ÄÈçÏÂ
chen.shÄÚÈÝ
#!/bin/bash
echo "ÕýÔÚÆô¶¯ÍøÒ³·þÎñÆ÷"
service apache2 start
sleep 2
#³õʼ»¯Mysql Êý¾Ý¿â
if [ ! -f "/var/lib/mysql/initialized" ]; then
mysqld --initialize-insecure
echo "ÕýÔÚ³õʼ»¯MYSQLÊý¾Ý¿â"
chown -R mysql:mysql /var/lib/mysql /var/run/mysqld /var/log/mysql
service mysql start
echo "ÕýÔÚÆô¶¯MYSQLÊý¾Ý¿â,ÉèÖÃÃÜÂëºÍÔ¶³Ì"
sleep 5
mysql -uroot --skip-password <<EOF
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "$MYSQL_ROOT_PASSWORD";
create user 'root'@'%' identified by "$MYSQL_ROOT_PASSWORD";
grant all privileges on *.* to 'root'@'%' with grant option;
FLUSH PRIVILEGES;
quit
EOF
mysql -uroot --skip-password <<EOF
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "$MYSQL_ROOT_PASSWORD";
create user 'root'@'%' identified by "$MYSQL_ROOT_PASSWORD";
grant all privileges on *.* to 'root'@'%' with grant option;
FLUSH PRIVILEGES;
quit
EOF
echo "MYSQL³õʼ»¯Íê³É,ÕýÔÚдÈë±êÖ¾Îļþ"
touch /var/lib/mysql/initialized
echo "ÕýÔڹرÕMYSQL·þÎñÆ÷"
service mysql stop
fi
#Æô¶¯ Mysql ·þÎñÆ÷
echo "ÕýÔÚÆô¶¯MYSQL·þÎñÆ÷"
service mysql start
mysql -uroot --skip-password <<EOF
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "$MYSQL_ROOT_PASSWORD";
create user 'root'@'%' identified by "$MYSQL_ROOT_PASSWORD";
grant all privileges on *.* to 'root'@'%' with grant option;
FLUSH PRIVILEGES;
quit
EOF
echo "MYSQL³õʼ»¯Íê³É,ÕýÔÚдÈë±êÖ¾Îļþ"
touch /var/lib/mysql/initialized
echo "ÕýÔڹرÕMYSQL·þÎñÆ÷"
service mysql stop
fi
#´´½¨·ûºÅÁ´½Ó
if [ ! -L /var/www/html/phpmyadmin ]; then
ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
fi
#Æô¶¯ Mysql ·þÎñÆ÷
echo "ÕýÔÚÆô¶¯MYSQL·þÎñÆ÷"
service mysql start